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.optionalVia
Source.optionalVia
Flow.optionalVia
Flow.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( Arrays.asList(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 is runs with defined elements
backpressures when the viaFlow runs for the defined elements and downstream backpressures
completes when the upstream completes
1.1.2+29-e21fa9eb*