pull-switch-map

1.0.0 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i pull-switch-map

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

4.17 kB

Total Files

4

Last publish

Collaborators

  • staltz