@basic-streams/chain-latest
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

@basic-streams/chain-latest

chainLatest<T, U>(fn: (x: T) => Stream<U>, stream: Stream<T>): Stream<U>

Same as chain, but when we create a new intermediate stream, we unsubscribe from the previous one.

import ofMany from "@basic-streams/of-many"
import chainLatest from "@basic-streams/chain-latest"

const stream = ofMany([1, 2], 10000)
const fn = x => ofMany([x, x, x], 7000)

const result = chainLatest(fn, stream)

result(x => {
  console.log(x)
})

// > 1
// > 2
// > 2
// > 2

// stream: _________1_________2
// fn(1):            ______1__!
// fn(2):                      ______2______2______2
// result: ________________1_________2______2______2

Package Sidebar

Install

npm i @basic-streams/chain-latest

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

5.15 kB

Total Files

8

Last publish

Collaborators

  • pozadi