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

x33g5p2x  于2022-01-25 转载在 其他  
字(3.7k)|赞(0)|评价(0)|浏览(133)

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

Observable.scanWith介绍

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

This sort of function is sometimes called an accumulator.

Note that the ObservableSource that results from this method will emit the value returned by the seedSupplier as its first item. Scheduler: scanWith does not operate by default on a particular Scheduler.
[中]返回一个Observable,该函数将指定的累加器函数应用于源ObservableSource发出的第一项和种子值,然后将该函数的结果与源ObservableSource发出的第二项一起馈送到同一个函数中,依此类推,直到源ObservableSource发出所有项,发出每个迭代的结果。
这种函数有时被称为累加器。
请注意,此方法产生的ObservableSource将发出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

public final <R> Observable<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> Observable<R> scan(final R initialValue, BiFunction<R, ? super T, R> accumulator) {
  ObjectHelper.requireNonNull(initialValue, "seed is null");
  return scanWith(Functions.justCallable(initialValue), accumulator);

代码示例来源:origin: akarnokd/akarnokd-misc

public static void main(String[] args) {
    Observable.range(1, 10)
    .scanWith(() -> new ArrayList<>(), (a, b) -> { a.add(b); return a; })
    .takeUntil(a -> a.size() == 5)
    .takeLast(1)
    .subscribe(System.out::println);
  }
}

代码示例来源:origin: radixdlt/radixdlt-java

public AddressTokenReducer(RadixAddress address, ParticleStore particleStore) {
  this.state = particleStore.getConsumables(address)
    .filter(p -> !(p instanceof AtomFeeConsumable))
    .scanWith(HashMap<RadixHash, AbstractConsumable>::new, (map, p) -> {
      HashMap<RadixHash, AbstractConsumable> newMap = new HashMap<>(map);
      newMap.put(p.getHash(), p);
      return newMap;
    })
    .map(map -> map.values().stream()
      .filter(AbstractConsumable::isConsumable)
      .map(AbstractConsumable::getAsConsumable)
      .collect(Collectors.toList())
    )
    .debounce(1000, TimeUnit.MILLISECONDS)
    .map(consumables -> {
      long balanceInSubUnits = consumables.stream().mapToLong(Consumable::getSignedQuantity).sum();
      Amount balance = Amount.subUnitsOf(balanceInSubUnits, Asset.TEST);
      return new AddressTokenState(balance, consumables);
    })
    .replay(1)
    .autoConnect();
}

相关文章

Observable类方法