tsducer
v0.2.3
Published
TypeScript transducer library
Downloads
13
Readme
tsducer
Example
import * as tsd from 'tsducer';
const xf = tsd.compose(
tsd.filter((x: number) => x % 2 !== 0),
tsd.map((x) => x * 2),
tsd.map((x) => x.toString()),
tsd.take(2)
);
const tTransform = tsd.transduce(xf, tsd.append, [] as string[]);
const iTransform = tsd.into([], xf);
tTransform([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); // -> ['2', '6']
iTransform([], xf)([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) // -> ['2', '6']
[...tsd.sequence(xf, [1 ,2, 3, 4, 5, 6, 7, 8, 9, 10])] // -> ['2', '6']
References
https://clojure.org/reference/transducers