Produce a value from a callback. When the callback returns undefined it is considered done.
const callback = () => Math.random();const f = Chains.From.func(callback);for await (const v of f) { // v is a new random number} Copy
const callback = () => Math.random();const f = Chains.From.func(callback);for await (const v of f) { // v is a new random number}
In the context of a chain:
let produced = 0;const chain = Chains.chain<number, string>( // Produce incrementing numbers Chains.From.func(() => produced++), // Convert to `x:0`, `x:1` ... Chains.transform(v => `x:${ v }`), // Take first 5 results Chains.cap(5));const data = await Chains.asArray(chain); Copy
let produced = 0;const chain = Chains.chain<number, string>( // Produce incrementing numbers Chains.From.func(() => produced++), // Convert to `x:0`, `x:1` ... Chains.transform(v => `x:${ v }`), // Take first 5 results Chains.cap(5));const data = await Chains.asArray(chain);
Produce a value from a callback. When the callback returns undefined it is considered done.
In the context of a chain: