Reputation: 12900
How to achieve a behavior similar to combineLatest with Highland? It looks like there is nothing similar in the library
Upvotes: 0
Views: 64
Reputation: 12900
My naive implementation is below:
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))
But I have no concerns about performance of such solution
Upvotes: 1