本文整理汇总了Java中io.reactivex.Flowable.zip方法的典型用法代码示例。如果您正苦于以下问题:Java Flowable.zip方法的具体用法?Java Flowable.zip怎么用?Java Flowable.zip使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.Flowable
的用法示例。
在下文中一共展示了Flowable.zip方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: zipWith
import io.reactivex.Flowable; //导入方法依赖的package包/类
@Override
public DataStream<Tuple> zipWith(DataStream... streams) {
Objects.requireNonNull(streams, NULL_STREAM_MESSAGE);
List<Flowable<?>> toBeZipped = new ArrayList<>();
List<DataStream> previous = new ArrayList<>();
toBeZipped.add(this.flow);
previous.add(this);
for (DataStream d : streams) {
Objects.requireNonNull(d, NULL_STREAM_MESSAGE);
toBeZipped.add(d.flow());
previous.add(d);
}
Flowable<Data<Tuple>> flowable = Flowable.zip(toBeZipped, objects -> {
List<Object> payloads = new ArrayList<>();
Data<?> first = null;
for (Object o : objects) {
if (!(o instanceof Data)) {
throw new IllegalArgumentException("Invalid incoming item - " + Data.class.getName() + " expected, received " +
o.getClass().getName());
} else {
if (first == null) {
first = ((Data) o);
}
payloads.add(((Data) o).payload());
}
}
if (first == null) {
throw new IllegalStateException("Invalid set of stream");
}
return first.with(Tuple.tuple(payloads.toArray(new Object[payloads.size()])));
});
DataStreamImpl<Object, Tuple> next = new DataStreamImpl<>(previous, flowable);
this.setDownstreams(next);
Arrays.stream(streams).forEach(d -> d.setDownstreams(next));
return next;
}
示例2: zip
import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test
public void zip() throws Exception{
Consumer<Object> consumer = v -> System.out.println("[" + System.currentTimeMillis() / 100 + "] " + v);
Flowable<Long> f1 = Flowable.interval(100, TimeUnit.MILLISECONDS);
Flowable<Long> f2 = Flowable.interval(200, TimeUnit.MILLISECONDS);
Flowable<Long> f3 = Flowable.zip(f1, f2, (x, y) -> x * 10000 + y);
f3.subscribe(consumer);
}