示例#1
0
 /**
  * Gather up all of the strings in to one string to be able to use it as one message. Don't use
  * this on infinite streams.
  *
  * @param src
  * @return
  */
 public static Observable<String> stringConcat(Observable<String> src) {
   return src.reduce(
       new Func2<String, String, String>() {
         @Override
         public String call(String a, String b) {
           return a + b;
         }
       });
 }
  @Test(timeout = 30000)
  public void testIssue1527() throws InterruptedException {
    // https://github.com/Netflix/RxJava/pull/1527
    Observable<Integer> source = Observable.just(1, 2, 3, 4, 5, 6);
    Observable<Integer> reduced =
        source.reduce(
            new Func2<Integer, Integer, Integer>() {
              @Override
              public Integer call(Integer i1, Integer i2) {
                return i1 + i2;
              }
            });

    Integer r = reduced.toBlocking().first();
    assertEquals(21, r.intValue());
  }
 @Override
 public Observable<Histogram> call(Observable<Histogram> window) {
   return window.reduce(distributionAggregator);
 }