Source.cycle
Stream iterator in cycled manner.
Signature
Description
Stream iterator in cycled manner. Internally a new iterator is being created to cycle the one provided via argument meaning when the original iterator runs out of elements to process it will start all over again from the beginning of the iterator provided by the evaluation of provided parameter. If the method argument provides an empty iterator the stream will be terminated with an exception.
Examples
- Scala
-
source
Source .cycle(() => List(1, 2, 3).iterator) .grouped(9) .runWith(Sink.head) // This will produce the Seq(1, 2, 3, 1, 2, 3, 1, 2, 3)
- Java
When iterator is empty the stream will be terminated with IllegalArgumentException
- Scala
-
source
val empty = Iterator.empty Source .cycle(() => empty) .runWith(Sink.head) // This will return a failed future with an `IllegalArgumentException`
- Java
Reactive Streams semantics
emits the next value returned from cycled iterator
completes never