本文整理了Java中io.reactivex.Flowable.flatMapIterable()
方法的一些代码示例,展示了Flowable.flatMapIterable()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Flowable.flatMapIterable()
方法的具体详情如下:
包路径:io.reactivex.Flowable
类名称:Flowable
方法名:flatMapIterable
[英]Returns a Flowable that merges each item emitted by the source Publisher with the values in an Iterable corresponding to that item that is generated by a selector.
Backpressure: The operator honors backpressure from downstream. The source Publishers is expected to honor backpressure as well. If the source Publisher violates the rule, the operator will signal a MissingBackpressureException. Scheduler: flatMapIterable does not operate by default on a particular Scheduler.
[中]返回一个可流动项,该可流动项将源发布服务器发出的每个项与选择器生成的该项对应的Iterable中的值合并。
背压:操作员接受来自下游的背压。预计出版者也会接受背压。如果源发布服务器违反规则,操作员将发出MissingBackpressureException信号。计划程序:默认情况下,FlatMapiteTable不会在特定计划程序上运行。
代码示例来源:origin: ReactiveX/RxJava
@Override
public Object apply(Flowable<Integer> f) throws Exception {
return f.flatMapIterable(new Function<Object, Iterable<Integer>>() {
@Override
public Iterable<Integer> apply(Object v) throws Exception {
return Arrays.asList(10, 20);
}
});
}
}, false, 1, 1, 10, 20);
代码示例来源:origin: ReactiveX/RxJava
@Override
public Publisher<Object> apply(Flowable<Object> f)
throws Exception {
return f.flatMapIterable(Functions.justFunction(Collections.emptyList()));
}
});
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void flatMapIterableCombinerNull() {
just1.flatMapIterable(new Function<Integer, Iterable<Integer>>() {
@Override
public Iterable<Integer> apply(Integer v) {
return Arrays.asList(1);
}
}, null);
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void flatMapIterableMapperNull() {
just1.flatMapIterable(null);
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void flatMapIterableMapperReturnsNull() {
just1.flatMapIterable(new Function<Integer, Iterable<Object>>() {
@Override
public Iterable<Object> apply(Integer v) {
return null;
}
}).blockingSubscribe();
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void flatMapIterableMapperIterableOneNull() {
just1.flatMapIterable(new Function<Integer, Iterable<Integer>>() {
@Override
public Iterable<Integer> apply(Integer v) {
return Arrays.asList(1, null);
}
}).blockingSubscribe();
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void flatMapIterableCombinerReturnsNull() {
just1.flatMapIterable(new Function<Integer, Iterable<Integer>>() {
@Override
public Iterable<Integer> apply(Integer v) {
return Arrays.asList(1);
}
}, new BiFunction<Integer, Integer, Object>() {
@Override
public Object apply(Integer a, Integer b) {
return null;
}
}).blockingSubscribe();
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void flatMapIterableMapperIteratorNull() {
just1.flatMapIterable(new Function<Integer, Iterable<Object>>() {
@Override
public Iterable<Object> apply(Integer v) {
return new Iterable<Object>() {
@Override
public Iterator<Object> iterator() {
return null;
}
};
}
}).blockingSubscribe();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void badRequest() {
TestHelper.assertBadRequestReported(Flowable.never().flatMapIterable(Functions.justFunction(Collections.emptyList())));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void callableThrows() {
Flowable.fromCallable(new Callable<Object>() {
@Override
public Object call() throws Exception {
throw new TestException();
}
})
.flatMapIterable(Functions.justFunction(Arrays.asList(1, 2, 3)))
.test()
.assertFailure(TestException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void smallPrefetch() {
Flowable.just(1, 2, 3)
.flatMapIterable(Functions.justFunction(Arrays.asList(1, 2, 3)), 1)
.test()
.assertResult(1, 2, 3, 1, 2, 3, 1, 2, 3);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void smallPrefetch2() {
Flowable.just(1, 2, 3).hide()
.flatMapIterable(Functions.justFunction(Collections.emptyList()), 1)
.test()
.assertResult();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void flatMapIterablePrefetch() {
Flowable.just(1, 2)
.flatMapIterable(new Function<Integer, Iterable<Integer>>() {
@Override
public Iterable<Integer> apply(Integer t) throws Exception {
return Arrays.asList(t * 10);
}
}, 1)
.test()
.assertResult(10, 20);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void take() {
Flowable.range(1, 3)
.flatMapIterable(Functions.justFunction(Arrays.asList(1)), 1)
.take(1)
.test()
.assertResult(1);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void fusedSourceCrash() {
Flowable.range(1, 3)
.map(new Function<Integer, Object>() {
@Override
public Object apply(Integer v) throws Exception {
throw new TestException();
}
})
.flatMapIterable(Functions.justFunction(Collections.emptyList()), 1)
.test()
.assertFailure(TestException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void oneByOne() {
Flowable.range(1, 3).hide()
.flatMapIterable(Functions.justFunction(Arrays.asList(1)), 1)
.rebatchRequests(1)
.test()
.assertResult(1, 1, 1);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void normalViaFlatMap() {
TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
Flowable.range(1, 5).flatMapIterable(mapper)
.subscribe(ts);
ts.assertValues(1, 2, 2, 3, 3, 4, 4, 5, 5, 6);
ts.assertNoErrors();
ts.assertComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void normalPrefetchViaFlatMap() {
TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
Flowable.range(1, 5).flatMapIterable(mapper, 2)
.subscribe(ts);
ts.assertValues(1, 2, 2, 3, 3, 4, 4, 5, 5, 6);
ts.assertNoErrors();
ts.assertComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void fusionRejected() {
TestSubscriber<Integer> ts = SubscriberFusion.newTest(QueueFuseable.ANY);
Flowable.just(1, 2, 3).hide()
.flatMapIterable(new Function<Integer, Iterable<Integer>>() {
@Override
public Iterable<Integer> apply(Integer v) throws Exception {
return Arrays.asList(1, 2);
}
})
.subscribe(ts);
SubscriberFusion.assertFusion(ts, QueueFuseable.NONE)
.assertResult(1, 2, 1, 2, 1, 2);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void doubleShare() {
Iterable<Integer> it = Flowable.range(1, 300).blockingIterable();
Flowable.just(it, it)
.flatMapIterable(Functions.<Iterable<Integer>>identity())
.share()
.share()
.count()
.test()
.assertResult(600L);
}
内容来源于网络,如有侵权,请联系作者删除!