本文整理了Java中reactor.core.publisher.Flux.zipWithIterable()
方法的一些代码示例,展示了Flux.zipWithIterable()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Flux.zipWithIterable()
方法的具体详情如下:
包路径:reactor.core.publisher.Flux
类名称:Flux
方法名:zipWithIterable
[英]Zip elements from this Flux with the content of an Iterable, that is to say combine one element from each, pairwise, into a Tuple2.
[中]将此流量中的元素与Iterable的内容压缩,也就是说,将每个元素中的一个元素成对组合成一个Tuple2。
代码示例来源:origin: reactor/reactor-core
/**
* Zip elements from this {@link Flux} with the content of an {@link Iterable}, that is
* to say combine one element from each, pairwise, into a {@link Tuple2}.
*
* <p>
* <img class="marble" src="doc-files/marbles/zipWithIterableForFlux.svg" alt="">
*
* @param iterable the {@link Iterable} to zip with
* @param <T2> the value type of the other iterable sequence
*
* @return a zipped {@link Flux}
*
*/
@SuppressWarnings("unchecked")
public final <T2> Flux<Tuple2<T, T2>> zipWithIterable(Iterable<? extends T2> iterable) {
return zipWithIterable(iterable, tuple2Function());
}
代码示例来源:origin: reactor/reactor-core
@Override
protected List<Scenario<String, String>> scenarios_operatorSuccess() {
return Arrays.asList(
scenario(f -> f.zipWithIterable(Arrays.asList(1, 2, 3), (a, b) -> a)),
scenario(f -> f.zipWithIterable(Arrays.asList(1, 2, 3, 4, 5), (a, b) -> a))
);
}
代码示例来源:origin: reactor/reactor-core
@Test(expected = NullPointerException.class)
public void zipperNull() {
Flux.never()
.zipWithIterable(Collections.emptyList(), null);
}
代码示例来源:origin: reactor/reactor-core
@Test(expected = NullPointerException.class)
public void iterableNull() {
Flux.never()
.zipWithIterable(null, (a, b) -> a);
}
代码示例来源:origin: reactor/reactor-core
@Test(expected = NullPointerException.class)
public void nullIterable() {
Flux.never().zipWithIterable(null);
}
代码示例来源:origin: reactor/reactor-core
@Test
public void emptyIterable() {
StepVerifier.create(Flux.never().zipWithIterable(new ArrayList<>()))
.verifyComplete();
}
代码示例来源:origin: reactor/reactor-core
@Override
protected List<Scenario<String, String>> scenarios_operatorError() {
return Arrays.asList(
scenario(f -> f.zipWithIterable(() -> {
throw exception();
}, (a, b) -> a)),
scenario(f -> f.zipWithIterable(Arrays.asList(1, 2, 3), (a, b) -> {
throw exception();
})),
scenario(f -> f.zipWithIterable(() ->
new Iterator<String>(){
@Override
scenario(f -> f.zipWithIterable(() ->
new Iterator<String>(){
@Override
scenario(f -> f.zipWithIterable(() ->
new Iterator<String>(){
boolean invoked;
代码示例来源:origin: reactor/reactor-core
@Test
public void zipperThrowsNull() {
AssertSubscriber<Object> ts = AssertSubscriber.create();
Flux.range(1, 5)
.zipWithIterable(
Arrays.asList(10, 20, 30, 40, 50), (a, b) -> { throw new RuntimeException("forced failure"); }).subscribe(ts);
ts.assertNoValues()
.assertNotComplete()
.assertError(RuntimeException.class)
.assertErrorWith( e -> Assert.assertTrue(e.getMessage().contains("forced failure")));
}
代码示例来源:origin: reactor/reactor-core
@Test
public void iterableThrowsNull() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
Flux.range(1, 5)
.zipWithIterable(
() -> { throw new RuntimeException("forced failure"); }, (a, b) -> a).subscribe(ts);
ts.assertNoValues()
.assertNotComplete()
.assertError(RuntimeException.class)
.assertErrorWith( e -> Assert.assertTrue(e.getMessage().contains("forced failure")));
}
代码示例来源:origin: reactor/reactor-core
@Test
@SuppressWarnings("unchecked")
public void zipWithIterable(){
StepVerifier.create(Flux.just(0).zipWithIterable(Arrays.asList(1, 2, 3)))
.expectNext(Tuples.of(0, 1))
.verifyComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void normalOtherShorter() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
Flux.range(1, 5)
.zipWithIterable(
Arrays.asList(10, 20, 30, 40), (a, b) -> a + b).subscribe(ts);
ts.assertValues(11, 22, 33, 44)
.assertComplete()
.assertNoError();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void normalSourceShorter() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
Flux.range(1, 4)
.zipWithIterable(
Arrays.asList(10, 20, 30, 40, 50), (a, b) -> a + b).subscribe(ts);
ts.assertValues(11, 22, 33, 44)
.assertComplete()
.assertNoError();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void zipperReturnsNull() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
Flux.range(1, 5)
.zipWithIterable(
Arrays.asList(10, 20, 30, 40, 50), (a, b) -> (Integer)null).subscribe(ts);
ts.assertNoValues()
.assertNotComplete()
.assertError(NullPointerException.class);
}
代码示例来源:origin: reactor/reactor-core
@Test
public void normalSameSize() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
Flux.range(1, 5)
.zipWithIterable(
Arrays.asList(10, 20, 30, 40, 50), (a, b) -> a + b).subscribe(ts);
ts.assertValues(11, 22, 33, 44, 55)
.assertComplete()
.assertNoError();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void sourceEmpty() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
Flux.range(1, 0)
.zipWithIterable(
Arrays.asList(10, 20, 30, 40), (a, b) -> a + b).subscribe(ts);
ts.assertNoValues()
.assertComplete()
.assertNoError();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void otherEmpty() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
Flux.range(1, 5)
.zipWithIterable(
Collections.<Integer>emptyList(), (a, b) -> a + b).subscribe(ts);
ts.assertNoValues()
.assertComplete()
.assertNoError();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void iterableReturnsNull() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
Flux.range(1, 5)
.zipWithIterable(
() -> null, (a, b) -> a).subscribe(ts);
ts.assertNoValues()
.assertNotComplete()
.assertError(NullPointerException.class);
}
代码示例来源:origin: reactor/reactor-core
@Test
public void normalSameSizeBackpressured() {
AssertSubscriber<Integer> ts = AssertSubscriber.create(0);
Flux.range(1, 5)
.zipWithIterable(
Arrays.asList(10, 20, 30, 40, 50), (a, b) -> a + b).subscribe(ts);
ts.assertNoValues()
.assertNoError()
.assertNotComplete();
ts.request(1);
ts.assertValues(11)
.assertNoError()
.assertNotComplete();
ts.request(2);
ts.assertValues(11, 22, 33)
.assertNoError()
.assertNotComplete();
ts.request(5);
ts.assertValues(11, 22, 33, 44, 55)
.assertComplete()
.assertNoError();
}
代码示例来源:origin: com.aol.cyclops/cyclops-reactor
/**
* @param iterable
* @param zipper
* @return
* @see reactor.core.publisher.Flux#zipWithIterable(java.lang.Iterable, java.util.function.BiFunction)
*/
public final <T2, V> Flux<V> zipWithIterable(Iterable<? extends T2> iterable,
BiFunction<? super T, ? super T2, ? extends V> zipper) {
return boxed.zipWithIterable(iterable, zipper);
}
代码示例来源:origin: com.aol.cyclops/cyclops-reactor
@Override
public <U, R> ReactiveSeq<R> zipS(Stream<? extends U> other, BiFunction<? super T, ? super U, ? extends R> zipper) {
if(other instanceof Publisher){
return zipP((Publisher<U>)other,zipper);
}
return flux(flux.zipWithIterable(ReactiveSeq.fromStream((Stream<U>)other),zipper));
}
内容来源于网络,如有侵权,请联系作者删除!