本文整理了Java中io.reactivex.Flowable.fromArray()
方法的一些代码示例,展示了Flowable.fromArray()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Flowable.fromArray()
方法的具体详情如下:
包路径:io.reactivex.Flowable
类名称:Flowable
方法名:fromArray
[英]Converts an Array into a Publisher that emits the items in the Array.
Backpressure: The operator honors backpressure from downstream and iterates the given arrayon demand (i.e., when requested). Scheduler: fromArray does not operate by default on a particular Scheduler.
[中]将阵列转换为发出阵列中项目的发布服务器。
背压:操作员接受来自下游的背压,并迭代给定的阵列需求(即,在请求时)。调度程序:默认情况下,fromArray不会在特定调度程序上运行。
代码示例来源:origin: ReactiveX/RxJava
Flowable<Integer> create(int n) {
Integer[] array = new Integer[n];
for (int i = 0; i < n; i++) {
array[i] = i;
}
return Flowable.fromArray(array);
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public Publisher<Long> createPublisher(long elements) {
return
Flowable.fromArray(array(elements))
;
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public Flowable<String> apply(Resource resource) {
return Flowable.fromArray(resource.getTextFromWeb().split(" "));
}
};
代码示例来源:origin: ReactiveX/RxJava
@Override
public Flowable<String> apply(Resource res) {
return Flowable.fromArray(res.getTextFromWeb().split(" "));
}
};
代码示例来源:origin: ReactiveX/RxJava
@Override
public Flowable<String> apply(Resource resource) {
return Flowable.fromArray(resource.getTextFromWeb().split(" "));
}
};
代码示例来源:origin: ReactiveX/RxJava
@Override
public Flowable<String> apply(Resource res) {
return Flowable.fromArray(res.getTextFromWeb().split(" "));
}
};
代码示例来源:origin: ReactiveX/RxJava
@Test
public void just() {
Flowable<Integer> source = Flowable.fromArray(new Integer[] { 1 });
Assert.assertTrue(source.getClass().toString(), source instanceof ScalarCallable);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testConcat() {
Subscriber<String> subscriber = TestHelper.mockSubscriber();
final String[] o = { "1", "3", "5", "7" };
final String[] e = { "2", "4", "6" };
final Flowable<String> odds = Flowable.fromArray(o);
final Flowable<String> even = Flowable.fromArray(e);
Flowable<String> concat = Flowable.concat(odds, even);
concat.subscribe(subscriber);
verify(subscriber, times(7)).onNext(anyString());
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public Flowable<String> apply(Resource resource) {
return Flowable.fromArray(resource.getTextFromWeb().split(" "))
.concatWith(Flowable.<String>error(new RuntimeException()));
}
};
代码示例来源:origin: ReactiveX/RxJava
@Test
public void fromArray() {
String[] items = new String[] { "one", "two", "three" };
assertEquals((Long)3L, Flowable.fromArray(items).count().blockingGet());
assertEquals("two", Flowable.fromArray(items).skip(1).take(1).blockingSingle());
assertEquals("three", Flowable.fromArray(items).takeLast(1).blockingSingle());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testElementAtFlowable() {
assertEquals(2, Flowable.fromArray(1, 2).elementAt(1).toFlowable().blockingSingle()
.intValue());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testFollowingFirst() {
Flowable<Integer> f = Flowable.fromArray(1, 3, 5, 6);
Single<Boolean> allOdd = f.all(new Predicate<Integer>() {
@Override
public boolean test(Integer i) {
return i % 2 == 1;
}
});
assertFalse(allOdd.blockingGet());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void directComparer() {
Flowable.fromArray(1, 2, 2, 3, 2, 4, 1, 1, 2)
.distinctUntilChanged(new BiPredicate<Integer, Integer>() {
@Override
public boolean test(Integer a, Integer b) {
return a.equals(b);
}
})
.test()
.assertResult(1, 2, 3, 2, 4, 1, 2);
}
代码示例来源:origin: ReactiveX/RxJava
@SuppressWarnings("unchecked")
@Test
public void toSortedList() {
TestSubscriber<List<Integer>> ts = new TestSubscriber<List<Integer>>();
Flowable.fromArray(10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
.parallel()
.toSortedList(Functions.naturalComparator())
.subscribe(ts);
ts.assertResult(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void conditionalOneIsNullSlowPath() {
Flowable.fromArray(new Integer[] { null, 1 })
.filter(Functions.alwaysTrue())
.test(2L)
.assertFailure(NullPointerException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void conditionalOneIsNull() {
Flowable.fromArray(new Integer[] { null, 1 })
.filter(Functions.alwaysTrue())
.test()
.assertFailure(NullPointerException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testWithFollowingFirstFlowable() {
Flowable<Integer> f = Flowable.fromArray(1, 3, 5, 6);
Flowable<Boolean> anyEven = f.any(new Predicate<Integer>() {
@Override
public boolean test(Integer i) {
return i % 2 == 0;
}
}).toFlowable();
assertTrue(anyEven.blockingFirst());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void conditionalOneByOne() {
Flowable.fromArray(new Integer[] { 1, 2, 3, 4, 5 })
.filter(Functions.alwaysTrue())
.rebatchRequests(1)
.test()
.assertResult(1, 2, 3, 4, 5);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void syncArray() {
Flowable.fromArray(new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 })
.to(SubscriberFusion.<Integer>test(Long.MAX_VALUE, QueueFuseable.ANY, false))
.assertOf(SubscriberFusion.<Integer>assertFusionMode(QueueFuseable.SYNC))
.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
.assertNoErrors()
.assertComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void syncArrayHidden() {
Flowable.fromArray(new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 })
.hide()
.to(SubscriberFusion.<Integer>test(Long.MAX_VALUE, QueueFuseable.ANY, false))
.assertOf(SubscriberFusion.<Integer>assertNotFuseable())
.assertOf(SubscriberFusion.<Integer>assertFusionMode(QueueFuseable.NONE))
.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
.assertNoErrors()
.assertComplete();
}
内容来源于网络,如有侵权,请联系作者删除!