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]));How the snippet works
The snippet’s external surface is compose, map, filter, prop, sortBy, all of it via ramda.
Module-level bindings hold the data — orders, applyLoyalty, summarize, raise — with no function scope in between.
Caveats
- Plan for an install step:
ramdais a real dependency, resolved by the package manager.
Statements that matter
const raise = curry((amount, order) =>
over(lensPath(['total']), add(amount), order),
);
const applyLoyalty = curry((rate, order) =>
over(lensPath(['total']), add(Math.round(order.total * rate)), order),
);
Interactive Tools for This Topic
Docker Run to Compose ConverterTransform docker run CLI commands with ports, environment variables, volumes, networks, and resource limits into clean compose.yaml service definitions.SRI Hash GeneratorGenerate Subresource Integrity (SRI) hashes from resource content using SHA-256, SHA-384, or SHA-512, and copy a ready-to-use script tag.
FAQ
- Does this require external packages?
- Yes — `ramda`. Add it to your project before running the snippet.
Report a problem with this exampleOpens a pre-filled issue on GitHub.