简体   繁体   English

Highland.js中的CombineLatest

[英]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 但我不担心这种解决方案的性能

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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