Sink.lastOption
Materialize a Future[Option[T]]
CompletionStage<Optional<T>>
which completes with the last value emitted wrapped in an Some
Optional
when the stream completes.
Description
Materialize a Future[Option[T]]
CompletionStage<Optional<T>>
which completes with the last value emitted wrapped in an Some
Optional
when the stream completes. if the stream completes with no elements the CompletionStage
is completed with None
an empty Optional
.
cancels never
backpressures never
Example
- Scala
-
source
val source = Source.empty[Int] val result: Future[Option[Int]] = source.runWith(Sink.lastOption) result.map(println) // None
- Java
-
source
Source<Integer, NotUsed> source = Source.empty(); CompletionStage<Optional<Integer>> result = source.runWith(Sink.lastOption(), materializer); result.thenAccept(System.out::println); // Optional.empty