Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.x: fix scan() not accepting a null initial value #3485

Merged
merged 1 commit into from
Nov 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/main/java/rx/internal/operators/OperatorScan.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
* <p>
* Note that when you pass a seed to {@code scan} the resulting Observable will emit that seed as its
* first emitted item.
*
* @param <R> the aggregate and output type
* @param <T> the input value type
*/
public final class OperatorScan<R, T> implements Operator<R, T> {

Expand Down Expand Up @@ -192,7 +195,7 @@ public InitialProducer(R initialValue, Subscriber<? super R> child) {
q = new SpscLinkedAtomicQueue<Object>(); // new SpscUnboundedAtomicArrayQueue<R>(8);
}
this.queue = q;
q.offer(initialValue);
q.offer(NotificationLite.instance().next(initialValue));
}

@Override
Expand Down
35 changes: 35 additions & 0 deletions src/test/java/rx/internal/operators/OperatorScanTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -391,4 +391,39 @@ public Integer call(Integer t1, Integer t2) {
ts.assertNotCompleted();
ts.assertValue(0);
}

@Test
public void testInitialValueNull() {
TestSubscriber<Integer> ts = TestSubscriber.create();

Observable.range(1, 10).scan(null, new Func2<Integer, Integer, Integer>() {
@Override
public Integer call(Integer t1, Integer t2) {
if (t1 == null) {
return t2;
}
return t1 + t2;
}
}).subscribe(ts);

ts.assertValues(null, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55);
ts.assertNoErrors();
ts.assertCompleted();
}

@Test
public void testEverythingIsNull() {
TestSubscriber<Integer> ts = TestSubscriber.create();

Observable.range(1, 6).scan(null, new Func2<Integer, Integer, Integer>() {
@Override
public Integer call(Integer t1, Integer t2) {
return null;
}
}).subscribe(ts);

ts.assertValues(null, null, null, null, null, null, null);
ts.assertNoErrors();
ts.assertCompleted();
}
}