summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/Iterator.scala
diff options
context:
space:
mode:
authorAleksandar Prokopec <axel22@gmail.com>2012-05-01 15:00:27 +0200
committerAleksandar Prokopec <axel22@gmail.com>2012-05-01 15:00:27 +0200
commit5f29da78e954d93e5bc8b878565de8c2a2abe561 (patch)
tree0ef8d37ad1a12cc5d84ca635eff696f2500a0010 /src/library/scala/collection/Iterator.scala
parentce04a62391bdc879db0eca015a420711e1a07212 (diff)
downloadscala-5f29da78e954d93e5bc8b878565de8c2a2abe561.tar.gz
scala-5f29da78e954d93e5bc8b878565de8c2a2abe561.tar.bz2
scala-5f29da78e954d93e5bc8b878565de8c2a2abe561.zip
Widen types in signatures of Future companion methods, refactor OnceCanBuildFrom.
Removed the implicit modifier on the OnceCanBuildFrom, as we don't support implicit classes with zero arguments. Added an implicit OnceCanBuildFrom method. The idea behind OnceCanBuildFrom is for it to be used by methods which construct collections, but are defined outside of collection classes. OnceCanBuildFrom so far worked only for objects of type TraversableOnce: shuffle(List(1, 2, 3).iterator: TraversableOnce[Int]) but this used to result in an implicit resolution error: shuffle(List(1, 2, 3).iterator) because after the type parameter M for `shuffle` was inferred to Iterator, no implicit of type CanBuildFrom[Iterator[_], A, Iterator[A]] could be found. Introduced another CanBuildFrom to the Iterator companion object. Modified Future tests appropriately.
Diffstat (limited to 'src/library/scala/collection/Iterator.scala')
-rw-r--r--src/library/scala/collection/Iterator.scala8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/library/scala/collection/Iterator.scala b/src/library/scala/collection/Iterator.scala
index 65de60c8fe..af83291a46 100644
--- a/src/library/scala/collection/Iterator.scala
+++ b/src/library/scala/collection/Iterator.scala
@@ -21,6 +21,14 @@ import immutable.Stream
*/
object Iterator {
+ /** With the advent of `TraversableOnce` and `Iterator`, it can be useful to have a builder which
+ * operates on `Iterator`s so they can be treated uniformly along with the collections.
+ * See `scala.util.Random.shuffle` for an example.
+ */
+ implicit def IteratorCanBuildFrom[A] = new TraversableOnce.BufferedCanBuildFrom[A, Iterator] {
+ def toColl[B](coll: ArrayBuffer[B]) = coll.iterator
+ }
+
/** The iterator which produces no values. */
val empty: Iterator[Nothing] = new AbstractIterator[Nothing] {
def hasNext: Boolean = false