Skip to content

Commit c4d995d

Browse files
authored
3.x: Add Completable.sequenceEqual (#6884)
1 parent 78c70d6 commit c4d995d

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

Diff for: src/main/java/io/reactivex/rxjava3/core/Completable.java

+24-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import io.reactivex.rxjava3.internal.operators.completable.*;
3030
import io.reactivex.rxjava3.internal.operators.maybe.*;
3131
import io.reactivex.rxjava3.internal.operators.mixed.*;
32-
import io.reactivex.rxjava3.internal.operators.single.SingleDelayWithCompletable;
32+
import io.reactivex.rxjava3.internal.operators.single.*;
3333
import io.reactivex.rxjava3.observers.TestObserver;
3434
import io.reactivex.rxjava3.plugins.RxJavaPlugins;
3535
import io.reactivex.rxjava3.schedulers.Schedulers;
@@ -414,6 +414,29 @@ public static Completable create(@NonNull CompletableOnSubscribe source) {
414414
return RxJavaPlugins.onAssembly(new CompletableCreate(source));
415415
}
416416

417+
/**
418+
* Compares two {@link CompletableSource}s and emits {@code true} via a {@link Single} if both complete.
419+
* <p>
420+
* <img width="640" height="187" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Completable.sequenceEqual.png" alt="">
421+
* <dl>
422+
* <dt><b>Scheduler:</b></dt>
423+
* <dd>{@code sequenceEqual} does not operate by default on a particular {@link Scheduler}.</dd>
424+
* </dl>
425+
* @param source1 the first {@code CompletableSource} instance
426+
* @param source2 the second {@code CompletableSource} instance
427+
* @return the new {@code Single} instance
428+
* @throws NullPointerException if {@code source1} or {@code source2} is {@code null}
429+
* @since 3.0.0
430+
*/
431+
@CheckReturnValue
432+
@NonNull
433+
@SchedulerSupport(SchedulerSupport.NONE)
434+
public static Single<Boolean> sequenceEqual(@NonNull CompletableSource source1, @NonNull CompletableSource source2) { // NOPMD
435+
Objects.requireNonNull(source1, "source1 is null");
436+
Objects.requireNonNull(source2, "source2 is null");
437+
return mergeArrayDelayError(source1, source2).andThen(Single.just(true));
438+
}
439+
417440
/**
418441
* Constructs a {@code Completable} instance by wrapping the given source callback
419442
* <strong>without any safeguards; you should manage the lifecycle and response
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Copyright (c) 2016-present, RxJava Contributors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5+
* compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is
10+
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
11+
* the License for the specific language governing permissions and limitations under the License.
12+
*/
13+
14+
package io.reactivex.rxjava3.internal.operators.completable;
15+
16+
import org.junit.Test;
17+
18+
import io.reactivex.rxjava3.core.Completable;
19+
import io.reactivex.rxjava3.exceptions.TestException;
20+
21+
public class CompletableSequenceEqualTest {
22+
23+
@Test
24+
public void bothComplete() {
25+
Completable.sequenceEqual(Completable.complete(), Completable.complete())
26+
.test()
27+
.assertResult(true);
28+
}
29+
30+
@Test
31+
public void firstFails() {
32+
Completable.sequenceEqual(Completable.error(new TestException()), Completable.complete())
33+
.test()
34+
.assertFailure(TestException.class);
35+
}
36+
37+
@Test
38+
public void secondFails() {
39+
Completable.sequenceEqual(Completable.complete(), Completable.error(new TestException()))
40+
.test()
41+
.assertFailure(TestException.class);
42+
}
43+
}

0 commit comments

Comments
 (0)