Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object Stream extends SeqFactory[Stream] {
- /** The factory for streams.
- * @note Methods such as map/flatMap will not invoke the Builder factory,
- * but will return a new stream directly, to preserve laziness.
- * The new stream is then cast to the factory's result type.
- * This means that every CanBuildFrom that takes a
- * Stream as its From type parameter must yield a stream as its result parameter.
- * If that assumption is broken, cast errors might result.
- */
- class StreamCanBuildFrom[A] extends GenericCanBuildFrom[A]
- implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Stream[A]] = new StreamCanBuildFrom[A]
- /** Creates a new builder for a stream */
- def newBuilder[A]: Builder[A, Stream[A]] = new StreamBuilder[A]
- import scala.collection.{Iterable, Seq, IndexedSeq}
- /** A builder for streams
- * @note This builder is lazy only in the sense that it does not go downs the spine
- * of traversables that are added as a whole. If more laziness can be achieved,
- * this builder should be bypassed.
- */
- class StreamBuilder[A] extends scala.collection.mutable.LazyBuilder[A, Stream[A]] {
- def result: Stream[A] = parts.toStream flatMap (_.toStream)
- }
- object Empty extends Stream[Nothing] {
- override def isEmpty = true
- override def head = throw new NoSuchElementException("head of empty stream")
- override def tail = throw new UnsupportedOperationException("tail of empty stream")
- def tailDefined = false
- }
- /** The empty stream */
- override def empty[A]: Stream[A] = Empty
- }
Add Comment
Please, Sign In to add comment