Answer the question
In order to leave comments, you need to log in
How to improve function call code?
there is a code
How to make it more beautiful? const result = f0(f1(f2(f3(1000)),1),'test')
Answer the question
In order to leave comments, you need to log in
It seems that functional pipelines from libraries like Underscore, Ramda or whatever could be used here. You can also do transpilation using the Babel pipeline operator , which has not yet reached the standard. It all works like this:
// где-то в библиотеке
function pipe(...fns) {
return function (arg) {
let result = arg;
for (let i = 0; i < fns.length; i++) {
result = fns[i](result);
}
return result;
}
}
// в коде
const result = pipe(
f3,
f2,
_ => f1(_, 1),
_ => f0(_, 'test')
)(1000);
const result3 = f3(1000)
const result2 = f2(result1)
const result1 = f1(result2, 1)
const result0 = f0(result2, 'test')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question