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

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

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

Flowable.scanWith介绍

[英]Returns a Flowable that applies a specified accumulator function to the first item emitted by a source Publisher and a seed value, then feeds the result of that function along with the second item emitted by the source Publisher into the same function, and so on until all items have been emitted by the source Publisher, emitting the result of each of these iterations.

This sort of function is sometimes called an accumulator.

Note that the Publisher that results from this method will emit the value returned by the seedSupplier as its first item. Backpressure: The operator honors downstream backpressure and expects the source Publisher to honor backpressure as well. Violating this expectation, a MissingBackpressureException may get signaled somewhere downstream. Scheduler: scanWith does not operate by default on a particular Scheduler.
[中]返回一个可流动函数,该函数将指定的累加器函数应用于源发布服务器发出的第一个项和种子值,然后将该函数的结果与源发布服务器发出的第二个项一起提供给同一个函数,依此类推,直到源发布服务器发出所有项,发出每个迭代的结果。
这种函数有时称为累加器。
请注意,此方法产生的发布者将发出seedSupplier返回的值作为其第一项。背压:操作员接受下游背压,并希望源发布者也接受背压。违反此预期,可能会在下游某处发出缺少背压异常*的信号。调度程序:默认情况下,scanWith不会在特定调度程序上运行。

代码示例

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

@Test(expected = NullPointerException.class)
public void scanSeedSupplierNull() {
  just1.scanWith(null, new BiFunction<Object, Integer, Object>() {
    @Override
    public Object apply(Object a, Integer b) {
      return 1;
    }
  });
}

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

@Test(expected = NullPointerException.class)
public void scanSeedSupplierFunctionNull() {
  just1.scanWith(new Callable<Object>() {
    @Override
    public Object call() {
      return 1;
    }
  }, null);
}

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

@Test(expected = NullPointerException.class)
public void scanSeedSupplierReturnsNull() {
  just1.scanWith(new Callable<Object>() {
    @Override
    public Object call() {
      return null;
    }
  }, new BiFunction<Object, Integer, Object>() {
    @Override
    public Object apply(Object a, Integer b) {
      return 1;
    }
  }).blockingSubscribe();
}

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

@Test(expected = NullPointerException.class)
public void scanSeedSupplierFunctionReturnsNull() {
  just1.scanWith(new Callable<Object>() {
    @Override
    public Object call() {
      return 1;
    }
  }, new BiFunction<Object, Integer, Object>() {
    @Override
    public Object apply(Object a, Integer b) {
      return null;
    }
  }).blockingSubscribe();
}

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

@Test
public void testScanWithSeedWhenScanSeedProviderThrows() {
  final RuntimeException e = new RuntimeException();
  Flowable.just(1, 2, 3).scanWith(throwingCallable(e),
    SUM)
   .test()
   .assertError(e)
   .assertNoValues();
}

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

public final <R> Flowable<R> scan(final R initialValue, BiFunction<R, ? super T, R> accumulator) {
  ObjectHelper.requireNonNull(initialValue, "seed is null");
  return scanWith(Functions.justCallable(initialValue), accumulator);

代码示例来源:origin: redisson/redisson

public final <R> Flowable<R> scan(final R initialValue, BiFunction<R, ? super T, R> accumulator) {
  ObjectHelper.requireNonNull(initialValue, "seed is null");
  return scanWith(Functions.justCallable(initialValue), accumulator);

相关文章

Flowable类方法