diff --git a/rxjava-core/src/main/java/rx/Observable.java b/rxjava-core/src/main/java/rx/Observable.java index 0fd95c0068..9881b0267b 100644 --- a/rxjava-core/src/main/java/rx/Observable.java +++ b/rxjava-core/src/main/java/rx/Observable.java @@ -1511,6 +1511,50 @@ public static Observable zip(Observable w0, Observable w1 return _create(OperationZip.zip(w0, w1, reduceFunction)); } + + /** + * Determines whether two sequences are equal by comparing the elements pairwise. + * + * @param first observable to compare + * @param second observable to compare + * @param type of sequence + * @return sequence of booleans, true if two sequences are equal by comparing the elements pairwise; otherwise, false. + */ + public static Observable sequenceEqual(Observable first, Observable second) { + return sequenceEqual(first, second, new Func2() { + @Override + public Boolean call(T first, T second) { + return first.equals(second); + } + }); + } + + /** + * Determines whether two sequences are equal by comparing the elements pairwise using a specified equality function. + * + * @param first observable sequence to compare + * @param second observable sequence to compare + * @param equality a function used to compare elements of both sequences + * @param type of sequence + * @return sequence of booleans, true if two sequences are equal by comparing the elements pairwise; otherwise, false. + */ + private static Observable sequenceEqual(Observable first, Observable second, Func2 equality) { + return zip(first, second, equality); + } + + /** + * Determines whether two sequences are equal by comparing the elements pairwise using a specified equality function. + * + * @param first observable sequence to compare + * @param second observable sequence to compare + * @param equality a function used to compare elements of both sequences + * @param type of sequence + * @return sequence of booleans, true if two sequences are equal by comparing the elements pairwise; otherwise, false. + */ + private static Observable sequenceEqual(Observable first, Observable second, Object equality) { + return zip(first, second, equality); + } + /** * Returns an Observable that applies a function of your choosing to the combination of items * emitted, in sequence, by two other Observables, with the results of this function becoming the @@ -2345,5 +2389,18 @@ public Integer call(Integer t1, Integer t2) { verify(w).onNext(60); } + @Test + public void testSequenceEqual() { + Observable first = toObservable(1, 2, 3); + Observable second = toObservable(1, 2, 4); + @SuppressWarnings("unchecked") + Observer result = mock(Observer.class); + sequenceEqual(first, second).subscribe(result); + verify(result, times(2)).onNext(true); + verify(result, times(1)).onNext(false); + } + + + } }