W3cubDocs

/ReactiveX

SequenceEqual

determine whether two Observables emit the same sequence of items
Open interactive diagram on rxmarbles.com

Pass SequenceEqual two Observables, and it will compare the items emitted by each Observable, and the Observable it returns will emit true only if both sequences are the same (the same items, in the same order, with the same termination state).

See Also

Language-Specific Information

sequenceEqual

Pass sequenceEqual two Observables, and it will compare the items emitted by each Observable, and the Observable it returns will emit true only if both sequences terminate normally after emitting the same sequence of items in the same order; otherwise it will emit false. You can optionally pass a third parameter: a function that accepts two items and returns true if they are equal according to a standard of your choosing.

Sample Code

def firstfour = Observable.from([1, 2, 3, 4]);
def firstfouragain = Observable.from([1, 2, 3, 4]);
def firstfive = Observable.from([1, 2, 3, 4, 5]);
def firstfourscrambled = Observable.from([3, 2, 1, 4]);

println('firstfour == firstfive?');
Observable.sequenceEqual(firstfour, firstfive).subscribe({ println(it); });
println('firstfour == firstfouragain?');
Observable.sequenceEqual(firstfour, firstfouragain).subscribe({ println(it); });
println('firstfour == firstfourscrambled?');
Observable.sequenceEqual(firstfour, firstfourscrambled).subscribe({ println(it); });
firstfour == firstfive?
false
firstfour == firstfouragain?
true
firstfour == firstfourscrambled?
false

This operator does not by default operate on any particular Scheduler.

sequenceEqual

Pass sequenceEqual two Observables, and it will compare the items emitted by each Observable, and the Observable it returns will emit true only if both sequences terminate normally after emitting the same sequence of items in the same order; otherwise it will emit false. You can optionally pass a third parameter: a function that accepts two items and returns true if they are equal according to a standard of your choosing.

This operator does not by default operate on any particular Scheduler.

sequenceEqual

In RxJS, sequenceEqual is a method of a particular Observable instance, so you pass it exactly one other Observable to compare the instance to. You can optionally pass a second parameter: a function that accepts two items and returns true if they are equal according to a standard of your choosing. sequenceEqual returns an Observable that will emit a true if the two Observables emit the same set of items in the same order before completing, or a false otherwise.

Sample Code

var source1 = Rx.Observable.return(42);
var source2 = Rx.Observable.return(42);

var source = source1.sequenceEqual(source2);

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

sequenceEqual is found in each of the following distributions:

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

sequenceEqual requires one of the following distributions:

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

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