W3cubDocs

/ReactiveX

All

determine whether all items emitted by an Observable meet some criteria
Open interactive diagram on rxmarbles.com

Pass a predicate function to the All operator that accepts an item emitted by the source Observable and returns a boolean value based on an evaluation of that item. All returns an Observable that emits a single boolean value: true if and only if the source Observable terminates normally and every item emitted by the source Observable evaluated as true according to this predicate; false if any item emitted by the source Observable evaluates as false according to this predicate.

See Also

Language-Specific Information

all

RxGroovy implements this operator as all. It does not by default operate on any particular Scheduler. The following example shows how to use this operator:

Sample Code

numbers = Observable.from([1, 2, 3, 4, 5]);

println("all even?" )
numbers.all({ 0 == (it % 2) }).subscribe({ println(it); });

println("all positive?");
numbers.all({ 0 < it }).subscribe({ println(it); });
all even? 
false
all positive? 
true
all

RxJava 1.x implements this operator as all. It does not by default operate on any particular Scheduler.

all

RxJava 2.x implements this operator as all. It does not by default operate on any particular Scheduler.

every

RxJS implements this operator as every. The following example shows how to use this operator:

Sample Code

var source = Rx.Observable.of(1,2,3,4,5)
  .every(function (x) {
    return x < 6;
  });

var subscription = source.subscribe(
  function (x) { console.log('Next: %s', x); },
  function (err) { console.log('Error: %s', err); },
  function () { console.log('Completed'); });
Next: true
Completed

every is found in the following distributions:

  • rx.all.js
  • rx.all.compat.js
  • rx.aggregates.js

It requires one of the following distributions:

  • rx.js
  • rx.compat.js
  • rx.lite.js
  • rx.lite.compat.js

There is also a jortSort operator that performs a test on the entire sequence of items emitted by the source Observable. If those items are emitted in sorted order, upon the successful completion of the source Observable, the Observable returned from jortSort will emit true and then complete. If any of the items emitted by the source Observable is out of sort order, upon the successful completion of the source Observable, the Observable returned from jortSort will emit false and then complete.

There is also a jortSortUntil operator. It does not wait until the source Observable completes to evaluate its sequence for sortedness, as jortSort does, but waits until a second Observable emits an item to do so.

See also

Sample Code

var source = Rx.Observable.of(1,2,3,4) // already sorted
               .jortSort();

var subscription = source.subscribe(
  function (x) { console.log('Next: %s', x); },
  function (e) { console.log('Error: %s', e); },
  function ( ) { console.log('Completed'); });
Next: true
Completed
var source = Rx.Observable.of(3,1,2,4) // not sorted
               .jortSort();

var subscription = source.subscribe(
  function (x) { console.log('Next: %s', x); },
  function (e) { console.log('Error: %s', e); },
  function ( ) { console.log('Completed'); });
Next: false
Completed
var just = Rx.helpers.just;

var source = Rx.Observable.of(1,2,3,4) // already sorted
               .flatmap(function (x) {
                 return Rx.Observable.timer(1000).map(just(x));
               }).jortSortUntil(Rx.Observable.timer(3000);

var subscription = source.subscribe(
  function (x) { console.log('Next: %s', x); },
  function (e) { console.log('Error: %s', e); },
  function ( ) { console.log('Completed'); });
Next: true
Completed
var just = Rx.helpers.just;

var source = Rx.Observable.of(3,1,2,4) // not sorted
               .flatmap(function (x) {
                 return Rx.Observable.timer(1000).map(just(x));
               }).jortSortUntil(Rx.Observable.timer(3000);

var subscription = source.subscribe(
  function (x) { console.log('Next: %s', x); },
  function (e) { console.log('Error: %s', e); },
  function ( ) { console.log('Completed'); });
Next: false
Completed

jortSort and jortSortUntil are found in the following distribution:

  • rx.sorting.js

They require one of the following distributions:

  • rx.js
  • rx.compat.js
  • rx.lite.js
  • rx.lite.compat.js

© ReactiveX contributors
Licensed under the Apache License 2.0.
http://reactivex.io/documentation/operators/all.html