3 ms·
Can't javascript already do [this][1]? const thrush = (value, func, ...funcs) => func ? thrush(func(value), ...funcs) : value; // no new synta
by MathMonkeyMan 4y ago
Can't javascript already do [this][1]?
const thrush = (value, func, ...funcs) =>
func ? thrush(func(value), ...funcs) : value;
// no new syntax required
thrush(
envars,
Object.entries,
x => x.map(([key, val]) => `${key}=${val}`),
x => x.join(' '),
x => chalk.dim('$ ' + x, 'node', args.join(' ')),
console.log);
[1]: http://www.davidgoffredo.com/thrush.html http://www.davidgoffredo.com/thrush.html
- runald 4y agoThrush combinator is neat. Here's another without using recursion: const thrush2 = (value, ...funcs) => funcs.reduce((value, func) => func(value), value); const thrush3 = (value, ...funcs) => { for (const func of funcs) value = func(value); return value }
- MathMonkeyMan 4y agoReduce is perfect for this, nice point.