Adding example of headOption operator (#29717)

Co-authored-by: Johan Andrén <johan@markatta.com>
This commit is contained in:
Muskan Gupta 2020-10-12 12:57:46 +05:30 committed by GitHub
parent fb1c6ff253
commit 1ff619259f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 0 deletions

View file

@ -114,6 +114,15 @@ public class SinkDocExamples {
// #fold
}
static void headOptionExample() {
// #headoption
Source<Integer, NotUsed> source = Source.empty();
CompletionStage<Optional<Integer>> result = source.runWith(Sink.headOption(), system);
result.thenAccept(System.out::println);
// Optional.empty
// #headoption
}
static void ignoreExample() {
// #ignore
Source<String, NotUsed> lines = readLinesFromFile();