use of io.reactivex.rxjava3.functions.BiFunction in project RxJava by ReactiveX.
the class FlowableReduceTest method shouldReduceTo10Events.
/**
* Make sure an asynchronous reduce with flatMap works.
* Original Reactor-Core test case: https://gist.github.com/jurna/353a2bd8ff83f0b24f0b5bc772077d61
*/
@Test
public void shouldReduceTo10Events() {
final AtomicInteger count = new AtomicInteger();
Flowable.range(0, 10).flatMap(new Function<Integer, Publisher<String>>() {
@Override
public Publisher<String> apply(final Integer x) throws Exception {
return Flowable.range(0, 2).map(new Function<Integer, String>() {
@Override
public String apply(Integer y) throws Exception {
return blockingOp(x, y);
}
}).subscribeOn(Schedulers.io()).reduce(new BiFunction<String, String, String>() {
@Override
public String apply(String l, String r) throws Exception {
return l + "_" + r;
}
}).doOnSuccess(new Consumer<String>() {
@Override
public void accept(String s) throws Exception {
count.incrementAndGet();
System.out.println("Completed with " + s);
}
}).toFlowable();
}
}).blockingLast();
assertEquals(10, count.get());
}
use of io.reactivex.rxjava3.functions.BiFunction in project RxJava by ReactiveX.
the class ParallelReduceFullTest method error.
@Test
public void error() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
Flowable.<Integer>error(new TestException()).parallel().reduce(new BiFunction<Integer, Integer, Integer>() {
@Override
public Integer apply(Integer a, Integer b) throws Exception {
return a + b;
}
}).test().assertFailure(TestException.class);
assertTrue(errors.isEmpty());
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.functions.BiFunction in project RxJava by ReactiveX.
the class ParallelReduceFullTest method error2.
@Test
public void error2() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
ParallelFlowable.fromArray(Flowable.<Integer>error(new IOException()), Flowable.<Integer>error(new TestException())).reduce(new BiFunction<Integer, Integer, Integer>() {
@Override
public Integer apply(Integer a, Integer b) throws Exception {
return a + b;
}
}).test().assertFailure(IOException.class);
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
Aggregations