Sink.last

Materializes into a Future CompletionStage which will complete with the last value emitted when the stream completes.

Sink operators

Signature

def last[T]: Sink[T, Future[T]]

Description

Materializes into a Future CompletionStage which will complete with the last value emitted when the stream completes. If the stream completes with no elements the Future CompletionStage is failed.

cancels never

backpressures never

Example

Scala
val source = Source(1 to 10)
val result: Future[Int] = source.runWith(Sink.last)
result.map(println)
// 10
Java
Source<Integer, NotUsed> source = Source.from(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
CompletionStage<Integer> result = source.runWith(Sink.last(), materializer);
result.thenAccept(System.out::println);
// 10
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.