diff options
author | Paul Phillips <paulp@improving.org> | 2010-06-03 20:25:32 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-06-03 20:25:32 +0000 |
commit | bf17437453a72c1bad87cd4f5f6555b0beaee783 (patch) | |
tree | 7d0b92b5807c900513a7e21068dcc47a6b81de30 | |
parent | 67d0f1050f16d798692b6e1fa5260480e8a7c081 (diff) | |
download | scala-bf17437453a72c1bad87cd4f5f6555b0beaee783.tar.gz scala-bf17437453a72c1bad87cd4f5f6555b0beaee783.tar.bz2 scala-bf17437453a72c1bad87cd4f5f6555b0beaee783.zip |
Sorted out some buck passing among TraversableO...
Sorted out some buck passing among TraversableOnce and its subclasses
about how exactly one creates a Stream. This is a continuation of r22115
for #3516. Review by prokopec.
-rw-r--r-- | src/library/scala/collection/TraversableLike.scala | 9 | ||||
-rw-r--r-- | src/library/scala/collection/TraversableOnce.scala | 9 | ||||
-rw-r--r-- | src/library/scala/collection/immutable/List.scala | 1 |
3 files changed, 8 insertions, 11 deletions
diff --git a/src/library/scala/collection/TraversableLike.scala b/src/library/scala/collection/TraversableLike.scala index 88a6379da2..71e9b0f0e9 100644 --- a/src/library/scala/collection/TraversableLike.scala +++ b/src/library/scala/collection/TraversableLike.scala @@ -694,13 +694,8 @@ trait TraversableLike[+A, +Repr] extends HasNewBuilder[A, Repr] with Traversable } def toTraversable: Traversable[A] = thisCollection - def toIterator: Iterator[A] = toIterable.iterator - - /** Converts this $coll to a stream. - * $willNotTerminateInf - * @return a stream containing all elements of this $coll. - */ - def toStream: Stream[A] = toIterable.toStream + def toIterator: Iterator[A] = toStream.iterator + def toStream: Stream[A] = Stream.empty[A] ++ thisCollection /** Converts this $coll to a string. * @return a string representation of this collection. By default this diff --git a/src/library/scala/collection/TraversableOnce.scala b/src/library/scala/collection/TraversableOnce.scala index 1797ff39db..5d09b6d2c6 100644 --- a/src/library/scala/collection/TraversableOnce.scala +++ b/src/library/scala/collection/TraversableOnce.scala @@ -398,17 +398,20 @@ trait TraversableOnce[+A] { */ def toList: List[A] = new ListBuffer[A] ++= self toList - /** Converts this $coll to an iterable collection. + /** Converts this $coll to an iterable collection. Note that + * the choice of target Iterable must be lazy as this TraversableOnce + * may be lazy and unevaluated. + * * $willNotTerminateInf * @return an `Iterable` containing all elements of this $coll. */ def toIterable: Iterable[A] = toStream - /** Converts this $coll to a sequence. + /** Converts this $coll to a sequence. As with toIterable, it must be lazy. * $willNotTerminateInf * @return a sequence containing all elements of this $coll. */ - def toSeq: Seq[A] = toList + def toSeq: Seq[A] = toStream /** Converts this $coll to an indexed sequence. * $willNotTerminateInf diff --git a/src/library/scala/collection/immutable/List.scala b/src/library/scala/collection/immutable/List.scala index 26d5948f2c..7785d73175 100644 --- a/src/library/scala/collection/immutable/List.scala +++ b/src/library/scala/collection/immutable/List.scala @@ -244,7 +244,6 @@ sealed abstract class List[+A] extends LinearSeq[A] if (isEmpty) Stream.Empty else new Stream.Cons(head, tail.toStream) - /** Like <code>span</code> but with the predicate inverted. */ @deprecated("use `span { x => !p(x) }` instead") |