optionalVia
For a stream containing optional elements, transforms each element by applying the given viaFlow and passing the value downstream as an optional value.
Signature
Source.optionalViaSource.optionalVia Flow.optionalViaFlow.optionalVia
Description
For a stream containing optional elements, transforms each element by applying the given viaFlow and passing the value downstream as an optional value.
- Scala
-
source
Source.optionalVia( Source(List(Some("1"), None, None, Some("4"))), Flow.fromFunction { (string: String) => string.toInt } )(Keep.none).runForeach(println) // Some(1) // None // None // Some(4) - Java
-
source
Flow<String, Integer, NotUsed> flow = Flow.fromFunction(Integer::parseInt); Source<Optional<String>, NotUsed> source = Source.from( List.of(Optional.of("1"), Optional.empty(), Optional.empty(), Optional.of("4"))); Source.optionalVia(source, flow, Keep.none()).runForeach(System.out::println, system); // Optional[1] // Optional.empty // Optional.empty // Optional[4]
Reactive Streams semantics
emits while the provided viaFlow runs with defined elements
backpressures when the viaFlow runs for the defined elements and downstream backpressures
completes when the upstream completes
2.0.0-M4+135-10b706ce*