Sink.none

A Sink that will test the given predicate p for every received element and completes with the result.

Sink operators

Signature

Sink.none

Description

none operator applies a predicate function to assert each element received, it returns false if any element satisfy the assertion, otherwise it returns true.

It materializes into a Future (in Scala) or a CompletionStage (in Java) that completes with the last state when the stream has finished.

Notes that if source is empty, it will return true

A Sink that will test the given predicate p for every received element and

  • completes and returns Future of true if the predicate is false for all elements;
  • completes and returns Future of true if the stream is empty (i.e. completes before signalling any elements);
  • completes and returns Future of false if the predicate is true for any element.

The materialized value Future will be completed with the value true or false when the input stream ends, or completed with Failure if there is a failure signaled in the stream.

Example

This example tests all elements in the stream is <= 100.

Scala
Java
sourceval result: Future[Boolean] =
  Source(1 to 100)
    .runWith(Sink.none(_ > 100))
val noneMatch = Await.result(result, 3.seconds)
println(noneMatch)
// Expect prints:
// true
sourcefinal boolean noneMatch =
    Source.range(1, 100)
        .runWith(Sink.none(elem -> elem > 100), system)
        .toCompletableFuture()
        .get(3, TimeUnit.SECONDS);
System.out.println(noneMatch);
// Expect prints:
// true

Reactive Streams Semantics

Completes when upstream completes or the predicate p returns true

cancels when predicate p returns true

backpressures when the invocation of predicate p has not yet completed