programming style poll
Suppose you have a function called pipe:
const addTwoAndSquare = pipe(
x => x + 2,
x => x * x);
console.log(addTwoAndSquare(1)); // 9
What is your preferred implementation?
const pipe = (...fns) =>
x => fns.reduce((z, fn) => fn(z), x);
VS
const pipe = (...fns) => {
return (x) => {
let z = x;
for (let i = 0; i < fns.length; ++i)
z = fn(z);
});
return z;
};
};
re: programming style poll
@aschmitz formatting is hard, ok
re: programming style poll
re: programming style poll
@wallhackio You got there in the end!
re: programming style poll
@wallhackio I'm going for the "normal" approach because it provides more opportunities to tinker if necessary (profiling hooks, logging, etc.), whereas the reducer is cleaner... as long as it's all you ever actually need, otherwise you end up writing out the normal approach anyway.
re: programming style poll
@wallhackio I prefer the one that doesn't disappear while I'm trying to read it. 😛