Ramda Compose Functional Data Pipeline
Build point-free data transformation pipelines with Ramda compose, lens-based updates, and curried predicates that stay testable end to end.
Code
import { compose, map, filter, prop, sortBy, descend, lensPath, over, add, curry } from 'ramda';
const orders = [
{ id: 1, customer: 'ada', total: 120, status: 'paid' },
{ id: 2, customer: 'grace', total: 85, status: 'refunded' },
{ id: 3, customer: 'ada', total: 340, status: 'paid' },
];
const applyLoyalty = curry((rate, order) =>
over(lensPath(['total']), add(Math.round(order.total * rate)), order),
);
const summarize = compose(
map(prop('customer')),
sortBy(descend(prop('total'))),
map(applyLoyalty(0.1)),
filter((o) => o.status === 'paid'),
);
console.log(summarize(orders));
const raise = curry((amount, order) =>
over(lensPath(['total']), add(amount), order),
);
console.log(raise(5)(orders[0]));Report a problem with this exampleOpens a pre-filled issue on GitHub.