本文整理了Java中io.reactivex.Flowable.fromIterable()
方法的一些代码示例,展示了Flowable.fromIterable()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Flowable.fromIterable()
方法的具体详情如下:
包路径:io.reactivex.Flowable
类名称:Flowable
方法名:fromIterable
[英]Converts an Iterable sequence into a Publisher that emits the items in the sequence.
Backpressure: The operator honors backpressure from downstream and iterates the given iterableon demand (i.e., when requested). Scheduler: fromIterable does not operate by default on a particular Scheduler.
[中]将Iterable序列转换为发布者,该发布者发出序列中的项目。
背压:操作员接受来自下游的背压,并迭代给定的iterableon需求(即,在请求时)。调度程序:默认情况下,fromIterable不会在特定调度程序上运行。
代码示例来源:origin: ReactiveX/RxJava
@Override
public Flowable<Integer> apply(Integer t) {
return Flowable.fromIterable(Arrays.asList(t));
}
})
代码示例来源:origin: ReactiveX/RxJava
@Override
public Flowable<Long> apply(Long t) {
return Flowable.fromIterable(Arrays.asList(1L, 2L, 3L)).hide();
}
}).take(3)).subscribe(ts);
代码示例来源:origin: ReactiveX/RxJava
@Override
public Publisher<Long> createPublisher(long elements) {
return Flowable.fromIterable(iterate(elements));
}
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public Publisher<Long> createPublisher(long elements) {
return
Flowable.merge(
Flowable.fromIterable(iterate(elements / 2)),
Flowable.fromIterable(iterate(elements - elements / 2))
)
;
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testListViaFlowable() {
Flowable<String> w = Flowable.fromIterable(Arrays.asList("one", "two", "three"));
Single<List<String>> single = w.toList();
SingleObserver<List<String>> observer = TestHelper.mockSingleObserver();
single.subscribe(observer);
verify(observer, times(1)).onSuccess(Arrays.asList("one", "two", "three"));
verify(observer, Mockito.never()).onError(any(Throwable.class));
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public Publisher<Long> createPublisher(long elements) {
return
Flowable.concat(Flowable.just(
Flowable.fromIterable(iterate(elements / 2)),
Flowable.fromIterable(iterate(elements - elements / 2))
)
)
;
}
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public Publisher<Long> createPublisher(long elements) {
return
Flowable.merge(Flowable.just(
Flowable.fromIterable(iterate(elements / 2)),
Flowable.fromIterable(iterate(elements - elements / 2))
)
)
;
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testFlatMapTransformsMergeException() {
Flowable<Integer> onNext = Flowable.error(new TestException());
Flowable<Integer> onComplete = Flowable.fromIterable(Arrays.asList(4));
Flowable<Integer> onError = Flowable.fromIterable(Arrays.asList(5));
Flowable<Integer> source = Flowable.fromIterable(Arrays.asList(10, 20, 30));
Subscriber<Object> subscriber = TestHelper.mockSubscriber();
source.flatMap(just(onNext), just(onError), funcThrow0(onComplete)).subscribe(subscriber);
verify(subscriber).onError(any(TestException.class));
verify(subscriber, never()).onNext(any());
verify(subscriber, never()).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testTake1() {
Flowable<String> w = Flowable.fromIterable(Arrays.asList("one", "two", "three"));
Flowable<String> take = w.take(2);
Subscriber<String> subscriber = TestHelper.mockSubscriber();
take.subscribe(subscriber);
verify(subscriber, times(1)).onNext("one");
verify(subscriber, times(1)).onNext("two");
verify(subscriber, never()).onNext("three");
verify(subscriber, never()).onError(any(Throwable.class));
verify(subscriber, times(1)).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
@Ignore("Null values not allowed")
public void testSkipLastWithNull() {
Flowable<String> flowable = Flowable.fromIterable(Arrays.asList("one", null, "two")).skipLast(1);
Subscriber<String> subscriber = TestHelper.mockSubscriber();
flowable.subscribe(subscriber);
verify(subscriber, times(1)).onNext("one");
verify(subscriber, times(1)).onNext(null);
verify(subscriber, never()).onNext("two");
verify(subscriber, never()).onError(any(Throwable.class));
verify(subscriber, times(1)).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testWrappingMock() {
Flowable<Integer> oi = Flowable.fromIterable(Arrays.asList(1, 2));
Subscriber<Integer> mockSubscriber = TestHelper.mockSubscriber();
oi.subscribe(new TestSubscriber<Integer>(mockSubscriber));
InOrder inOrder = inOrder(mockSubscriber);
inOrder.verify(mockSubscriber, times(1)).onNext(1);
inOrder.verify(mockSubscriber, times(1)).onNext(2);
inOrder.verify(mockSubscriber, times(1)).onComplete();
inOrder.verifyNoMoreInteractions();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testWrappingMockWhenUnsubscribeInvolved() {
Flowable<Integer> oi = Flowable.fromIterable(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9)).take(2);
Subscriber<Integer> mockSubscriber = TestHelper.mockSubscriber();
oi.subscribe(new TestSubscriber<Integer>(mockSubscriber));
InOrder inOrder = inOrder(mockSubscriber);
inOrder.verify(mockSubscriber, times(1)).onNext(1);
inOrder.verify(mockSubscriber, times(1)).onNext(2);
inOrder.verify(mockSubscriber, times(1)).onComplete();
inOrder.verifyNoMoreInteractions();
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public Publisher<Long> createPublisher(long elements) {
return
Flowable.switchOnNext(Flowable.just(
Flowable.fromIterable(iterate(elements)))
)
;
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = IllegalArgumentException.class)
public void testTakeWithError() {
Flowable.fromIterable(Arrays.asList(1, 2, 3)).take(1)
.map(new Function<Integer, Integer>() {
@Override
public Integer apply(Integer t1) {
throw new IllegalArgumentException("some error");
}
}).blockingSingle();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void fusionRejected() {
TestSubscriber<Integer> ts = SubscriberFusion.newTest(QueueFuseable.ASYNC);
Flowable.fromIterable(Arrays.asList(1, 2, 3))
.subscribe(ts);
SubscriberFusion.assertFusion(ts, QueueFuseable.NONE)
.assertResult(1, 2, 3);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testAssert() {
Flowable<Integer> oi = Flowable.fromIterable(Arrays.asList(1, 2));
TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
oi.subscribe(ts);
ts.assertValues(1, 2);
ts.assertValueCount(2);
ts.assertTerminated();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testAssertNotMatchValue() {
Flowable<Integer> oi = Flowable.fromIterable(Arrays.asList(1, 2));
TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
oi.subscribe(ts);
thrown.expect(AssertionError.class);
// FIXME different message pattern
// thrown.expectMessage("Value at index: 1 expected to be [3] (Integer) but was: [2] (Integer)");
ts.assertValues(1, 3);
ts.assertValueCount(2);
ts.assertTerminated();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void assertNeverAtMatchingValue() {
Flowable<Integer> oi = Flowable.fromIterable(Arrays.asList(1, 2));
TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
oi.subscribe(ts);
ts.assertValues(1, 2);
thrown.expect(AssertionError.class);
ts.assertNever(2);
ts.assertValueCount(2);
ts.assertTerminated();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void normalConditionalCrash2() {
Flowable.fromIterable(new CrashingIterable(100, 100, 2))
.filter(Functions.alwaysTrue())
.test()
.assertFailure(TestException.class, 0);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void syncIterableHidden() {
Flowable.fromIterable(Arrays.asList(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();
}
}
内容来源于网络,如有侵权,请联系作者删除!