Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including @basic-streams/ap with all npm packages installed. Try it out:

var ap = require("@basic-streams/ap")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@basic-streams/ap v1.0.0

ap operator for basic-streams

@basic-streams/ap

ap<T, U>(streamf: Stream<(x: T) => U>, streamv: Stream<T>): Stream<U>

Creates a stream that will contain values created by applying the latest function from streamf to the latest value from streamv every time one of them updates.

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

const streamf = ofMany([x => x + 2, x => x - 2], 10000)
const streamv = ofMany([1, 2, 3], 8000)

const result = ap(streamf, streamv)

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

// > 3
// > 4
// > 0
// > 1

//               x => x + 2   x => x - 2
// streamf: _________._________.
// streamv: _______1_______2_______3
// result:  _________3_____4___0___1
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free