Hacker News new | ask | show | jobs
by thisone 3530 days ago
Let me give you a 'fer instance' (this may be the only one that exists, but it's one that had me WTFing until I found the correct documentation to read via stack overflow)

Calling grouped on a Seq.

I've been playing around with some API requests, and needed to batch a long Seq to make reasonable sized GET requests.

So I called grouped on a Seq, then to sanity check I called .length on the grouping.

Then suddenly I had an empty iterator.

Maybe I should have known better, yeah, but the documentation I was reading http://www.scala-lang.org/docu/files/collections-api/collect... doesn't mention this fact about iterators. Again, maybe I'm the only person in the world who didn't realise the problem with calling .length on what I thought of as a regular old batched set.

It wasn't until I hit on the right google combination that I found http://www.scala-lang.org/api/current/#scala.collection.Iter... from a stack overflow reference, and the lightbulb finally went on.

1 comments

Thanks for the example. We agree that this is a tricky part in the collections. For Scala 2.13, our headline feature will be simplifying/refining the collections API. One of the areas we'd like to improve is to make the transitions from eager to lazy more clear. Also, we'd like to keep immutable (more) separate from mutable collections. Once we switch gears from 2.12.0 to 2.13 milestones, we'll be sure to provide a convenient way to share gotchas like this, so we can see how to prevent them.