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

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

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

Observable.collectInto介绍

[英]Collects items emitted by the finite source ObservableSource into a single mutable data structure and returns a Single that emits this structure.

This is a simplified version of reduce that does not need to return the state on each pass.

Note that this operator requires the upstream to signal onComplete for the accumulator object to be emitted. Sources that are infinite and never complete will never emit anything through this operator and an infinite source may lead to a fatal OutOfMemoryError. Scheduler: collectInto does not operate by default on a particular Scheduler.
[中]将有限源ObservableSource发出的项收集到单个可变数据结构中,并返回发出此结构的单个数据结构。
这是reduce的简化版本,不需要在每次传递时返回状态。
请注意,此运算符要求上游发出信号,通知要发射的累加器对象完成。无限且永远不完整的源永远不会通过该运算符发出任何信息,而无限源可能会导致致命的OutOfMemory错误。调度器:默认情况下,collectInto不会在特定的调度器上运行。

代码示例

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

@Test(expected = NullPointerException.class)
public void collectIntoInitialNull() {
  just1.collectInto(null, new BiConsumer<Object, Integer>() {
    @Override
    public void accept(Object a, Integer b) { }
  });
}

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

@Test(expected = NullPointerException.class)
public void collectIntoCollectorNull() {
  just1.collectInto(1, null);
}

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

@SuppressWarnings("unchecked")
@Test
public void collectInto() {
  Observable.just(1, 1, 1, 1, 2)
  .collectInto(new HashSet<Integer>(), new BiConsumer<HashSet<Integer>, Integer>() {
    @Override
    public void accept(HashSet<Integer> s, Integer v) throws Exception {
      s.add(v);
    }
  })
  .test()
  .assertResult(new HashSet<Integer>(Arrays.asList(1, 2)));
}

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

@SuppressWarnings("unchecked")
@Test
public void collectIntoObservable() {
  Observable.just(1, 1, 1, 1, 2)
  .collectInto(new HashSet<Integer>(), new BiConsumer<HashSet<Integer>, Integer>() {
    @Override
    public void accept(HashSet<Integer> s, Integer v) throws Exception {
      s.add(v);
    }
  }).toObservable()
  .test()
  .assertResult(new HashSet<Integer>(Arrays.asList(1, 2)));
}

代码示例来源:origin: com.microsoft.azure/azure-storage-blob

.collectInto(new ArrayList<String>(numBlocks), ArrayList::add)

代码示例来源:origin: Azure/azure-storage-java

.collectInto(new ArrayList<String>(numBlocks), ArrayList::add)

相关文章

Observable类方法