pull-switch-map
v1.0.0
Published
pull-stream through, like flat-map but with inner cancellation
Downloads
8
Readme
pull-switch-map
npm install --save pull-switch-map
The pull-stream equivalent to RxJS's switchMap operator.
Description
In other words, this is essentially a map-and-flatten operation, but treats concurrency so that the outer stream is pulled concurrently at the same time as the inner stream is pulled, and once a new outer value is received, the current inner stream is aborted and swapped with the new inner stream.
Marble diagram:
interval(1000)
------------0------------1------------2------------3--------...
switchMap(x => interval(350))
---------------0---1---2----0---1---2----0---1---2----0---1-...
Arguments to switchMap(fn)
:
fn
: the mapping function that takes the value from the outer pull-stream and returns a new (inner) pull-stream
Usage
const pull = require('pull-stream')
const switchMap = require('pull-switch-map')
pull(
somesource(),
switchMap(x => pull.values([x])),
pull.drain(i => console.log(i))
)
License
MIT