Source.fromIterator
Stream the values from an Iterator
, requesting the next value when there is demand.
Signature
Source.fromIterator
Source.fromIterator
Description
Stream the values from an Iterator
, requesting the next value when there is demand. The iterator will be created anew for each materialization, which is the reason the method
factory
takes a function
Creator
rather than an Iterator
directly.
If the iterator perform blocking operations, make sure to run it on a separate dispatcher.
Example
- Scala
-
source
Source.fromIterator(() => (1 to 3).iterator).runForeach(println) // could print // 1 // 2 // 3
- Java
-
source
Source.fromIterator(() -> Arrays.asList(1, 2, 3).iterator()) .runForeach(System.out::println, system); // could print // 1 // 2 // 3
Reactive Streams semantics
emits the next value returned from the iterator
completes when the iterator reaches its end
1.1.2