如何将多个Streams合并成一个更高级别的Stream? [英] How can I merge multiple Streams into a higher level Stream?

查看:753
本文介绍了如何将多个Streams合并成一个更高级别的Stream?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个流, Stream< A> Stream< B> 。我有一个类型 C 的构造函数,它接受 A B 。如何将两个 Stream 合并到 Stream< C>

c> package c:package:async c $ c>将两个流组合成一个流对,然后从中创建 C 对象。

  importpackage:asyncshow StreamZip; 
...
Stream< C> createCs(Stream A as,Stream B bs)=>
new StreamZip([as,bs])map((ab)=> new C(ab [0],ab [1]


I have two streams, Stream<A> and Stream<B>. I have a constructor for a type C that takes an A and a B. How do I merge the two Streams into a Stream<C>?

解决方案

You can use StreamZip in package:async to combine two streams into one stream of pairs, then create the C objects from that.

import "package:async" show StreamZip;
...
Stream<C> createCs(Stream<A> as, Stream<B> bs) =>
  new StreamZip([as, bs]).map((ab) => new C(ab[0], ab[1]));

这篇关于如何将多个Streams合并成一个更高级别的Stream?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆