本文整理了Java中io.reactivex.Observable.withLatestFrom()
方法的一些代码示例,展示了Observable.withLatestFrom()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.withLatestFrom()
方法的具体详情如下:
包路径:io.reactivex.Observable
类名称:Observable
方法名:withLatestFrom
[英]Combines the value emission from this ObservableSource with the latest emissions from the other ObservableSources via a function to produce the output item.
Note that this operator doesn't emit anything until all other sources have produced at least one value. The resulting emission only happens when this ObservableSource emits (and not when any of the other sources emit, unlike combineLatest). If a source doesn't produce any value and just completes, the sequence is completed immediately.
Scheduler: This operator does not operate by default on a particular Scheduler.
[中]通过一个函数,将该可观测源的排放值与其他可观测源的最新排放值相结合,生成输出项。
请注意,在所有其他源产生至少一个值之前,此运算符不会发出任何内容。产生的发射只有在该可观测源发射时才会发生(而不是在任何其他源发射时,与CombineTest不同)。如果一个源没有产生任何值,只是完成了,那么序列就会立即完成。
调度器:默认情况下,该操作员不会对特定的调度器进行操作。
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void withLatestFromOtherNull() {
just1.withLatestFrom(null, new BiFunction<Integer, Object, Object>() {
@Override
public Object apply(Integer a, Object b) {
return 1;
}
});
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void withLatestFromCombinerNull() {
just1.withLatestFrom(just1, null);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void dispose() {
TestHelper.checkDisposed(Observable.just(1).withLatestFrom(Observable.just(2), new BiFunction<Integer, Integer, Object>() {
@Override
public Object apply(Integer a, Integer b) throws Exception {
return a;
}
}));
TestHelper.checkDisposed(Observable.just(1).withLatestFrom(Observable.just(2), Observable.just(3), new Function3<Integer, Integer, Integer, Object>() {
@Override
public Object apply(Integer a, Integer b, Integer c) throws Exception {
return a;
}
}));
}
代码示例来源:origin: ReactiveX/RxJava
@SuppressWarnings("unchecked")
@Test
public void combineToNull2() {
Observable.just(1)
.withLatestFrom(Arrays.asList(Observable.just(2), Observable.just(3)), new Function<Object[], Object>() {
@Override
public Object apply(Object[] o) throws Exception {
return null;
}
})
.test()
.assertFailure(NullPointerException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void manyCombinerThrows() {
Observable.just(1).withLatestFrom(Observable.just(2), Observable.just(3), new Function3<Integer, Integer, Integer, Object>() {
@Override
public Object apply(Integer a, Integer b, Integer c) throws Exception {
throw new TestException();
}
})
.test()
.assertFailure(TestException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void combineToNull1() {
Observable.just(1)
.withLatestFrom(Observable.just(2), new BiFunction<Integer, Integer, Object>() {
@Override
public Object apply(Integer a, Integer b) throws Exception {
return null;
}
})
.test()
.assertFailure(NullPointerException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void withLatestFromCombinerReturnsNull() {
just1.withLatestFrom(just1, new BiFunction<Integer, Integer, Object>() {
@Override
public Object apply(Integer a, Integer b) {
return null;
}
}).blockingSubscribe();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void zeroOtherCombinerReturnsNull() {
Observable.just(1)
.withLatestFrom(new Observable[0], Functions.justFunction(null))
.test()
.assertFailureAndMessage(NullPointerException.class, "The combiner returned a null value");
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void with4Others() {
Observable<Integer> just = Observable.just(1);
TestObserver<List<Integer>> to = new TestObserver<List<Integer>>();
just.withLatestFrom(just, just, just, just, new Function5<Integer, Integer, Integer, Integer, Integer, List<Integer>>() {
@Override
public List<Integer> apply(Integer a, Integer b, Integer c, Integer d, Integer e) {
return Arrays.asList(a, b, c, d, e);
}
})
.subscribe(to);
to.assertValue(Arrays.asList(1, 1, 1, 1, 1));
to.assertNoErrors();
to.assertComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void with2Others() {
Observable<Integer> just = Observable.just(1);
TestObserver<List<Integer>> to = new TestObserver<List<Integer>>();
just.withLatestFrom(just, just, new Function3<Integer, Integer, Integer, List<Integer>>() {
@Override
public List<Integer> apply(Integer a, Integer b, Integer c) {
return Arrays.asList(a, b, c);
}
})
.subscribe(to);
to.assertValue(Arrays.asList(1, 1, 1));
to.assertNoErrors();
to.assertComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void with3Others() {
Observable<Integer> just = Observable.just(1);
TestObserver<List<Integer>> to = new TestObserver<List<Integer>>();
just.withLatestFrom(just, just, just, new Function4<Integer, Integer, Integer, Integer, List<Integer>>() {
@Override
public List<Integer> apply(Integer a, Integer b, Integer c, Integer d) {
return Arrays.asList(a, b, c, d);
}
})
.subscribe(to);
to.assertValue(Arrays.asList(1, 1, 1, 1));
to.assertNoErrors();
to.assertComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void withMainError() {
TestObserver<String> to = new TestObserver<String>();
Observable.error(new TestException()).withLatestFrom(
new Observable<?>[] { Observable.just(1), Observable.just(1) }, toArray)
.subscribe(to);
to.assertNoValues();
to.assertError(TestException.class);
to.assertNotComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void manyIteratorThrows() {
Observable.just(1)
.withLatestFrom(new CrashingMappedIterable<Observable<Integer>>(1, 100, 100, new Function<Integer, Observable<Integer>>() {
@Override
public Observable<Integer> apply(Integer v) throws Exception {
return Observable.just(2);
}
}), new Function<Object[], Object>() {
@Override
public Object apply(Object[] a) throws Exception {
return a;
}
})
.test()
.assertFailureAndMessage(TestException.class, "iterator()");
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void withEmpty() {
TestObserver<String> to = new TestObserver<String>();
Observable.range(1, 3).withLatestFrom(
new Observable<?>[] { Observable.just(1), Observable.empty() }, toArray)
.subscribe(to);
to.assertNoValues();
to.assertNoErrors();
to.assertComplete();
}
代码示例来源:origin: ReactiveX/RxJava
ObjectHelper.requireNonNull(combiner, "combiner is null");
Function<Object[], R> f = Functions.toFunction(combiner);
return withLatestFrom(new ObservableSource[] { o1, o2 }, f);
代码示例来源:origin: ReactiveX/RxJava
@Test
public void withError() {
TestObserver<String> to = new TestObserver<String>();
Observable.range(1, 3).withLatestFrom(
new Observable<?>[] { Observable.just(1), Observable.error(new TestException()) }, toArray)
.subscribe(to);
to.assertNoValues();
to.assertError(TestException.class);
to.assertNotComplete();
}
代码示例来源:origin: ReactiveX/RxJava
ObjectHelper.requireNonNull(combiner, "combiner is null");
Function<Object[], R> f = Functions.toFunction(combiner);
return withLatestFrom(new ObservableSource[] { o1, o2, o3 }, f);
代码示例来源:origin: redisson/redisson
ObjectHelper.requireNonNull(combiner, "combiner is null");
Function<Object[], R> f = Functions.toFunction(combiner);
return withLatestFrom(new ObservableSource[] { o1, o2 }, f);
代码示例来源:origin: ReactiveX/RxJava
ObjectHelper.requireNonNull(combiner, "combiner is null");
Function<Object[], R> f = Functions.toFunction(combiner);
return withLatestFrom(new ObservableSource[] { o1, o2, o3, o4 }, f);
代码示例来源:origin: redisson/redisson
ObjectHelper.requireNonNull(combiner, "combiner is null");
Function<Object[], R> f = Functions.toFunction(combiner);
return withLatestFrom(new ObservableSource[] { o1, o2, o3 }, f);
内容来源于网络,如有侵权,请联系作者删除!