JSPM

pull-switch-map

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q22628F
  • License MIT

pull-stream through, like flat-map but with inner cancellation

Package Exports

  • pull-switch-map

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pull-switch-map) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

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