下面列出了io.reactivex.Flowable#range ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test
public void testLongReversed() {
for (int n = 1; n < 1000; n++) {
final int N = n;
Flowable<Integer> a = Flowable.range(1, n).map(new Function<Integer, Integer>() {
@Override
public Integer apply(Integer x) {
return N + 1 - x;
}
});
Flowable<Integer> b = Flowable.range(1, n);
boolean equals = Flowable.sequenceEqual(matchThem(a, b).sorted(), Flowable.range(1, n))
.blockingGet();
assertTrue(equals);
}
}
private static void flowableBlocking(){
Flowable<Integer> obs = Flowable.range(1,5);
Double d2 = obs.filter(i -> i % 2 == 0)
.doOnNext(System.out::println) //prints 2 and 4
.map(Math::sqrt)
.delay(100, TimeUnit.MILLISECONDS)
.blockingLast();
System.out.println(d2); //prints: 2.0
}
private void testShifted(int n, boolean async) {
Flowable<Integer> a = Flowable.just(0).concatWith(Flowable.range(1, n));
if (async) {
a = a.subscribeOn(Schedulers.computation());
}
Flowable<Integer> b = Flowable.range(1, n);
assertTrue(Flowable.sequenceEqual(matchThem(a, b), Flowable.range(1, n)).blockingGet());
}
@Test
public void givenFlowable_whenAssembled_shouldExecuteTheHook() {
RxJavaPlugins.setOnFlowableAssembly(flowable -> {
hookCalled = true;
return flowable;
});
Flowable.range(1, 10);
assertTrue(hookCalled);
}
@Outgoing("data")
public Publisher<Integer> source() {
return Flowable.range(0, 10);
}
@Outgoing("dyn-data")
public Publisher<Integer> source() {
return Flowable.range(0, 10);
}
@Outgoing("source")
public Flowable<Integer> source() {
return Flowable.range(0, 10);
}
@Outgoing("data")
public Publisher<Integer> source() {
return Flowable.range(0, 10);
}
@Outgoing("data")
public Publisher<Integer> source() {
return Flowable.range(0, 10);
}
@Outgoing("data")
public Publisher<Integer> source() {
return Flowable.range(0, 10);
}
@Setup
public void setup() {
baseline = Flowable.range(1, count);
justFlatMapRange = Flowable.just(1).flatMap(v -> Flowable.range(v, count));
Integer[] arr = new Integer[count];
Arrays.fill(arr, 777);
justFlatMapArray = Flowable.just(1).flatMap(v -> Flowable.fromArray(arr));
rangeFlatMapJust = Flowable.range(1, count).flatMap(v -> Flowable.just(v));
}