zip()

The point of this operator is to stitch as many values together as possible. We may be dealing with continuous streams, but also with streams that have a limit to the number of values they emit. You use this operator in the following way:

// combination/zip.js

let stream$ = Rx.Observable.of(1, 2, 3, 4);
let secondStream$ = Rx.Observable.of(5, 6, 7, 8);
let thirdStream$ = Rx.Observable.of(9, 10);

let zippedStream$ = Rx.Observable.zip(
stream$,
secondStream$,
thirdStream$
)

// [1, 5, 9] [2, 6, 10]
zippedStream$.subscribe(data => console.log(data))

As we can see, here, we stitch values together vertically, and by the least common denominator, thirdStream$ is the shortest, calculating the number of emitted values. This means we will take values from left to right and zip them together. As thirdStream$ only has two values, we end up with only two emits.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.91.37