Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Python version
- def stream(count):
- for i in range(count):
- print("Generating new object ({})".format(i))
- yield "string_{}".format(i)
- for item in stream(10):
- print(item)
- // Scala version
- def generate(count: Int): Iterator[String] = {
- def stream(current: Int): Stream[String] = {
- if (current < count) {
- s"string_$current" #:: stream(current + 1)
- } else {
- Stream.empty[String]
- }
- }
- stream(0).iterator
- }
- val stream: Iterator[String] = generate(10)
- while (stream.hasNext) {
- println(stream.next())
- }
Add Comment
Please, Sign In to add comment