Sink.lastOption

Materialize a Future[Option[T]] which completes with the last value emitted wrapped in an Some when the stream completes.

Sink operators

Signature

def lastOption[T]: Sink[T, Future[Option[T]]]

Description

Materialize a Future[Option[T]] which completes with the last value emitted wrapped in an Some when the stream completes. if the stream completes with no elements the CompletionStage is completed with None .

cancels never

backpressures never

Example

Scala
sourceval source = Source.empty[Int]
val result: Future[Option[Int]] = source.runWith(Sink.lastOption)
result.map(println)
// None
Java
sourceSource<Integer, NotUsed> source = Source.empty();
CompletionStage<Optional<Integer>> result = source.runWith(Sink.lastOption(), materializer);
result.thenAccept(System.out::println);
// Optional.empty
Found an error in this documentation? The source code for this page can be found here. Please feel free to edit and contribute a pull request.