I have a Scala function foo(bs : Stream[Bar]) : Bat that I need to call from Java code. How do I create the “bs” Stream (Stream[Bar]) in Java and lazily generate its Bar objects?
I have a Scala function foo(bs : Stream[Bar]) : Bat that I need to
Share
Depending on what needs to be in the stream, it might be easiest to create a
java.util.Iteratorand then convert this to aStreamvia ascala.collection.Iterator:The iterator doesn’t have to come from a collection, of course—we can just as easily create an infinite stream by implementing our own iterator:
It’s not as pretty as something like
Stream.iterate(0)(_ + 1).map(_.toString), but it works.