Search code examples
rxjsfrpbacon.jskefir.js

Stream of arrays into array of streams operator


In Rx.js, how to turn a stream of arrays into array of streams for example i have a stream of following:['0a','0b'], ['1a','1b'],['2a','2b','2c'] and i want to get the following streams:

0a---1a---2a--->
0b---1b---2b--->
          2c--->

Are there any operators for doing something like that or should I write one from scratch?


Solution

  • Something like this should work

    stream.
      flatMap(array =>
        Rx.Observable.from(
          array.map((obj, i) => {index: i, ...obj})
        )
      ).groupBy(x => x.index, ).
      subscribe(x =>
        x.map((x,i) => subscribe(x))
      )