简体   繁体   中英

CombineLatest in Highland.js

How to achieve a behavior similar to combineLatest with Highland? It looks like there is nothing similar in the library

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM