UNPKG

@thi.ng/transducers-async

Version:

Async versions of various highly composable transducers, reducers and iterators

14 lines (13 loc) 546 B
import { implementsFunction } from "@thi.ng/checks/implements-function"; import { isAsyncIterable } from "@thi.ng/checks/is-async-iterable"; import { isIterable } from "@thi.ng/checks/is-iterable"; import { illegalArgs } from "@thi.ng/errors/illegal-arguments"; const ensureAsyncTransducer = (x) => implementsFunction(x, "xformAsync") ? x.xformAsync() : x; const ensureIterable = (x) => { !(isIterable(x) || isAsyncIterable(x)) && illegalArgs(`value is not iterable: ${x}`); return x; }; export { ensureAsyncTransducer, ensureIterable };