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

1.0.0 • Public • Published

@basic-streams/map2

map2<A, B, C>(
  fn: (a: A, b: B) => C,
  streamA: Stream<A>,
  streamB: Stream<B>,
): Stream<C>

Creates a stream containing fn(a, b) where a and b are the latest values from streamA and streamB. The resulting stream updates when any of source stream update.

import ofMany from "@basic-streams/of-many"
import map2 from "@basic-streams/map2"

const streamA = ofMany([2, 4], 10000)
const streamB = ofMany([1, 3], 8000)
const result = map2((a, b) => a + b, streamA, streamB)

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

// > 3
// > 5
// > 7

// streamA: _________2_________4
// streamB: _______1_______3
// result:  _________3_____5___7

Dependencies (3)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i @basic-streams/map2

    Weekly Downloads

    2

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    4.46 kB

    Total Files

    8

    Last publish

    Collaborators

    • pozadi