isTraversableAgain is declared final in GenTraversableLike and with its plethora of Known Subclasses, I would like to know the usage of the function and the wisdom behind its being final.
1 Answer
That method is defined on GenTraversableOnce
, which is kind of a father to everything. Among that everything is Iterator
, which can only be traversed once, and everything else, which is expected to be traversable multiple times. Though, of course, you can go up to GenTraversableOnce
or TraversableOnce
and subclass it with something else that is only traversable once.
The methods declared on GenTraversableLike
rely on being able to traverse a collection multiple times.
-
ah... I trace isTraversableAgain from List and get to GenTraversableLike through linearization and miss the original source GenTraversableOnce. Thanks Daniel. Jan 3, 2012 at 20:11
-
The fact that it is a method implies that you might want to call it at runtime and make a decision about how to handle the collection based on the result. I'm having trouble imagining what situation that would be though I guess it is not impossible.– OwenJan 3, 2012 at 21:48
-
1@Owen
grep
? The methodtoArray
uses it to decide whether to copy the whole collection to an intermediate collection first (if false), or call size to initialize the array and then copy the collection. Jan 4, 2012 at 0:06