Created
September 28, 2010 19:41
-
-
Save jsuereth/601645 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> def data(block : Int => Unit) { for(i <- 0 to 10) block(i) } | |
data: (block: (Int) => Unit)Unit | |
scala> val x = new Traversable[Int] { | |
| def foreach[U](f : Int => U) = { | |
| data( f(_) : Unit) | |
| } | |
| } | |
x: java.lang.Object with Traversable[Int] = line15(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) | |
scala> x.toList.toStream | |
res6: scala.collection.immutable.Stream[Int] = Stream(0, ?) | |
scala> x.toStream | |
java.lang.StackOverflowError | |
at $anon$1.thisCollection(<console>:6) | |
at scala.collection.TraversableLike$class.toStream(TraversableLike.scala:701) | |
at $anon$1.toStream(<console>:6) | |
at scala.collection.immutable.Stream.$plus$plus(Stream.scala:141) | |
at scala.collection.TraversableLike$class.toStream(TraversableLike.scala:701) | |
at $anon$1.toStream(<console>:6) | |
at scala.collection.immutable.Stream.$plus$plus(Stream.scala:141) | |
at scala.collection.TraversableLike$class.toStream(TraversableLike.scala:701) | |
at $anon$1.toStream(<console>:6) | |
at scala.collection.immutable.Stream.$plus$plus(Stream.scala:141) | |
at scala.collection.TraversableLike$class.toStream(TraversableLike.scala:701) | |
at $anon$1.toStream(<console>:6) | |
at scala.collection.immutable.Stream.$plus$plus(Stream.scala:141) | |
at scal... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://stackoverflow.com/questions/3797699/generator-block-to-iterator-stream-conversion/3816012#3816012