@thi.ng/transducers
Version:
Collection of ~170 lightweight, composable transducers, reducers, generators, iterators for functional data transformations
21 lines (20 loc) • 436 B
JavaScript
import { isFunction } from "@thi.ng/checks/is-function";
const deepTransform = (spec) => {
if (isFunction(spec)) {
return spec;
}
const mapfns = Object.keys(spec[1] || {}).reduce(
(acc, k) => (acc[k] = deepTransform(spec[1][k]), acc),
{}
);
return (x) => {
const res = { ...x };
for (const k in mapfns) {
res[k] = mapfns[k](res[k]);
}
return spec[0](res);
};
};
export {
deepTransform
};