io.reactivex.Flowable.concatMapIterable()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(145)

本文整理了Java中io.reactivex.Flowable.concatMapIterable()方法的一些代码示例,展示了Flowable.concatMapIterable()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Flowable.concatMapIterable()方法的具体详情如下:
包路径:io.reactivex.Flowable
类名称:Flowable
方法名:concatMapIterable

Flowable.concatMapIterable介绍

[英]Returns a Flowable that concatenate 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: concatMapIterable does not operate by default on a particular Scheduler.
[中]返回一个Flowable,它将源发布服务器发出的每个项与选择器生成的该项对应的Iterable中的值连接起来。背压:操作员接受来自下游的背压。预计出版者也会接受背压。如果源发布服务器违反规则,操作员将发出MissingBackpressureException信号。调度程序:默认情况下,ConcatMapiteTable不会在特定调度程序上运行。

代码示例

代码示例来源:origin: ReactiveX/RxJava

  1. @Override
  2. public Publisher<Integer> createPublisher(long elements) {
  3. return
  4. Flowable.range(0, (int)elements)
  5. .concatMapIterable(new Function<Integer, Iterable<Integer>>() {
  6. @Override
  7. public Iterable<Integer> apply(Integer v) throws Exception {
  8. return Collections.singletonList(v);
  9. }
  10. })
  11. ;
  12. }
  13. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test(expected = NullPointerException.class)
  2. public void concatMapIterableNull() {
  3. just1.concatMapIterable(null);
  4. }

代码示例来源:origin: ReactiveX/RxJava

  1. /**
  2. * Returns a Flowable that concatenate each item emitted by the source Publisher with the values in an
  3. * Iterable corresponding to that item that is generated by a selector.
  4. *
  5. * <dl>
  6. * <dt><b>Backpressure:</b></dt>
  7. * <dd>The operator honors backpressure from downstream. The source {@code Publisher}s is
  8. * expected to honor backpressure as well. If the source {@code Publisher} violates the rule, the operator will
  9. * signal a {@code MissingBackpressureException}.</dd>
  10. * <dt><b>Scheduler:</b></dt>
  11. * <dd>{@code concatMapIterable} does not operate by default on a particular {@link Scheduler}.</dd>
  12. * </dl>
  13. *
  14. * @param <U>
  15. * the type of item emitted by the resulting Publisher
  16. * @param mapper
  17. * a function that returns an Iterable sequence of values for when given an item emitted by the
  18. * source Publisher
  19. * @return a Flowable that emits the results of concatenating the items emitted by the source Publisher with
  20. * the values in the Iterables corresponding to those items, as generated by {@code collectionSelector}
  21. * @see <a href="http://reactivex.io/documentation/operators/flatmap.html">ReactiveX operators documentation: FlatMap</a>
  22. */
  23. @CheckReturnValue
  24. @BackpressureSupport(BackpressureKind.FULL)
  25. @SchedulerSupport(SchedulerSupport.NONE)
  26. public final <U> Flowable<U> concatMapIterable(Function<? super T, ? extends Iterable<? extends U>> mapper) {
  27. return concatMapIterable(mapper, 2);
  28. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test(expected = NullPointerException.class)
  2. public void concatMapIterableReturnNull() {
  3. just1.concatMapIterable(new Function<Integer, Iterable<Object>>() {
  4. @Override
  5. public Iterable<Object> apply(Integer v) {
  6. return null;
  7. }
  8. }).blockingSubscribe();
  9. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test(expected = NullPointerException.class)
  2. public void concatMapIterableIteratorNull() {
  3. just1.concatMapIterable(new Function<Integer, Iterable<Object>>() {
  4. @Override
  5. public Iterable<Object> apply(Integer v) {
  6. return new Iterable<Object>() {
  7. @Override
  8. public Iterator<Object> iterator() {
  9. return null;
  10. }
  11. };
  12. }
  13. }).blockingSubscribe();
  14. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test
  2. public void concatMapIterableBufferSize() {
  3. Flowable.just(1, 2).concatMapIterable(new Function<Integer, Iterable<Integer>>() {
  4. @Override
  5. public Iterable<Integer> apply(Integer v) throws Exception {
  6. return Arrays.asList(1, 2, 3, 4, 5);
  7. }
  8. }, 1)
  9. .test()
  10. .assertResult(1, 2, 3, 4, 5, 1, 2, 3, 4, 5);
  11. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test
  2. public void longRunning() {
  3. TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
  4. int n = 1000 * 1000;
  5. Flowable.range(1, n).concatMapIterable(mapper)
  6. .subscribe(ts);
  7. ts.assertValueCount(n * 2);
  8. ts.assertNoErrors();
  9. ts.assertComplete();
  10. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test
  2. public void normal() {
  3. TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
  4. Flowable.range(1, 5).concatMapIterable(mapper)
  5. .subscribe(ts);
  6. ts.assertValues(1, 2, 2, 3, 3, 4, 4, 5, 5, 6);
  7. ts.assertNoErrors();
  8. ts.assertComplete();
  9. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test
  2. public void just() {
  3. TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
  4. Flowable.just(1).concatMapIterable(mapper)
  5. .subscribe(ts);
  6. ts.assertValues(1, 2);
  7. ts.assertNoErrors();
  8. ts.assertComplete();
  9. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test
  2. public void empty() {
  3. TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
  4. Flowable.<Integer>empty().concatMapIterable(mapper)
  5. .subscribe(ts);
  6. ts.assertNoValues();
  7. ts.assertNoErrors();
  8. ts.assertComplete();
  9. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test
  2. public void mixture() {
  3. TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
  4. Flowable.range(0, 1000)
  5. .concatMapIterable(new Function<Integer, Iterable<Integer>>() {
  6. @Override
  7. public Iterable<Integer> apply(Integer v) {
  8. return (v % 2) == 0 ? Collections.singleton(1) : Collections.<Integer>emptySet();
  9. }
  10. })
  11. .subscribe(ts);
  12. ts.assertValueCount(500);
  13. ts.assertNoErrors();
  14. ts.assertComplete();
  15. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test
  2. public void justHidden() {
  3. TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
  4. Flowable.just(1).hide().concatMapIterable(mapper)
  5. .subscribe(ts);
  6. ts.assertValues(1, 2);
  7. ts.assertNoErrors();
  8. ts.assertComplete();
  9. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test
  2. public void emptyInnerThenSingleBackpressured() {
  3. TestSubscriber<Integer> ts = new TestSubscriber<Integer>(1);
  4. Flowable.range(1, 2)
  5. .concatMapIterable(new Function<Integer, Iterable<Integer>>() {
  6. @Override
  7. public Iterable<Integer> apply(Integer v) {
  8. return v == 2 ? Collections.singleton(1) : Collections.<Integer>emptySet();
  9. }
  10. })
  11. .subscribe(ts);
  12. ts.assertValue(1);
  13. ts.assertNoErrors();
  14. ts.assertComplete();
  15. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test
  2. public void manyEmptyInnerThenSingleBackpressured() {
  3. TestSubscriber<Integer> ts = new TestSubscriber<Integer>(1);
  4. Flowable.range(1, 1000)
  5. .concatMapIterable(new Function<Integer, Iterable<Integer>>() {
  6. @Override
  7. public Iterable<Integer> apply(Integer v) {
  8. return v == 1000 ? Collections.singleton(1) : Collections.<Integer>emptySet();
  9. }
  10. })
  11. .subscribe(ts);
  12. ts.assertValue(1);
  13. ts.assertNoErrors();
  14. ts.assertComplete();
  15. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test
  2. public void asIntermediate() {
  3. TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
  4. int n = 1000 * 1000;
  5. Flowable.range(1, n).concatMapIterable(mapper).concatMap(new Function<Integer, Flowable<Integer>>() {
  6. @Override
  7. public Flowable<Integer> apply(Integer v) {
  8. return Flowable.just(v);
  9. }
  10. })
  11. .subscribe(ts);
  12. ts.assertValueCount(n * 2);
  13. ts.assertNoErrors();
  14. ts.assertComplete();
  15. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test
  2. public void error() {
  3. TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
  4. Flowable.<Integer>just(1).concatWith(Flowable.<Integer>error(new TestException()))
  5. .concatMapIterable(mapper)
  6. .subscribe(ts);
  7. ts.assertValues(1, 2);
  8. ts.assertError(TestException.class);
  9. ts.assertNotComplete();
  10. }

代码示例来源:origin: ReactiveX/RxJava

  1. .concatMapIterable(new Function<Integer, Iterable<Integer>>() {
  2. @Override
  3. public Iterable<Integer> apply(Integer v) {

代码示例来源:origin: ReactiveX/RxJava

  1. .concatMapIterable(new Function<Integer, Iterable<Integer>>() {
  2. @Override
  3. public Iterable<Integer> apply(Integer v) {

代码示例来源:origin: ReactiveX/RxJava

  1. .concatMapIterable(new Function<Integer, Iterable<Integer>>() {
  2. @Override
  3. public Iterable<Integer> apply(Integer v) {

代码示例来源:origin: ReactiveX/RxJava

  1. @Test
  2. public void normalBackpressured() {
  3. TestSubscriber<Integer> ts = new TestSubscriber<Integer>(0);
  4. Flowable.range(1, 5).concatMapIterable(mapper)
  5. .subscribe(ts);
  6. ts.assertNoValues();
  7. ts.assertNoErrors();
  8. ts.assertNotComplete();
  9. ts.request(1);
  10. ts.assertValue(1);
  11. ts.assertNoErrors();
  12. ts.assertNotComplete();
  13. ts.request(2);
  14. ts.assertValues(1, 2, 2);
  15. ts.assertNoErrors();
  16. ts.assertNotComplete();
  17. ts.request(7);
  18. ts.assertValues(1, 2, 2, 3, 3, 4, 4, 5, 5, 6);
  19. ts.assertNoErrors();
  20. ts.assertComplete();
  21. }

相关文章

Flowable类方法