-
-
Notifications
You must be signed in to change notification settings - Fork 11
fun
Eugene Lazutkin edited this page Sep 18, 2024
·
4 revisions
fun()
is an equivalent of gen(). It wraps a list of functions organized
as a sequential pipeline.
The differences with gen()
are:
- It returns an asynchronous function instead of an asynchronous generator function.
- Values produced by generator functions are collected in arrays and passed with
many()
of defs. See many values.
It exists mostly for backwards compatibility with older versions of stream-chain
and for
possible performance reasons.
import fun from 'stream-chain/fun.js';
import {getManyValues} from 'stream-chain/defs.js';
const chain = fun(
function* (n) { for (let i = 0; i < n; ++i) yield i; },
x => x * x
);
for (const i of getManyValues(await chain(3))) {
console.log(i); // 0, 1, 4
}