如何使用Highland实现类似于combineLatest的行为?看起来图书馆里没有类似的东西。
发布于 2015-12-16 02:03:12
我的简单实现如下:
var combineLatest = function(...streams) {
var _streams = streams.map(
(s, i) => s.map((x) => {return {[i]: x}})
)
return H(_streams).merge().scan1(H.extend).filter((obj) => {
return Object.keys(obj).length === streams.length
}).map(obj =>
_(obj).pairs().reduce(
(res, [key, val]) => {
res[key] = val
return res
},
[]
)
)
}
combineLatest(users, photos).each((x) => console.log(x))但我并不担心这种解决方案的性能。
https://stackoverflow.com/questions/34157498
复制相似问题