foldRight on infinite lazy structure
问题 According to http://en.wikipedia.org/wiki/Fold_(higher-order_function), a right fold can operate on infinite lists if the full list does not have to be evaluated. This can be seen in action in haskell: Prelude> take 5 (foldr (:) [] [1 ..]) [1,2,3,4,5] This does not seem to work well in scala for streams: Stream.from(1).foldRight(Stream.empty[Int])( (i, s) => i #:: s).take(5) // StackOverflowError or on iterators: Iterator.from(1).foldRight(Iterator.empty: Iterator[Int]){ (i, it) => Iterator