Review this generated currying and composition code against the stated task.
Build a reusable report function that filters by a minimum, keeps caller input unchanged, emits only public order data, defaults the label prefix to an empty string, and serializes after async metadata is ready.
JavaScript
function curry(fn) {
return function curried(...args) {
if (args.length >= fn.length) return fn(...args);
return (...next) => curried(...args, ...next);
};
}
const pipe = (...steps) => input =>
steps.reduce((value, step) => step(value), input);
const selectOrders = curry((minimum, options = {}, orders) => {
const kept = orders.filter(order => order.total >= minimum);
kept.sort((a, b) => b.total - a.total);
return kept.map(order => ({
...order,
label: options.prefix + order.id,
}));
});
const buildReport = minimum => pipe(
selectOrders(minimum),
async orders => ({ orders, generatedAt: Date.now() }),
report => JSON.stringify(report),
);
generated code is illustrative, not from any one model