I have a couple of functions that currently are written (in abstract form) like this...
const someFunction = x => f(g(x))(x);
i.e.
- pass
x
intog
to get the output. - Then pass that output into
f
to get afunction
. - And then pass
x
into thatfunction
.
It feels a bit clunky due to the nested brackets, the real world function names, and multiple uses of x
etc...
I've been using lodash/fp
and my first thought was _.flow
but then I'd still have to pass x
into the output of the flow in the end.
Hmm... unless I reverse the order of the parameters in f
then I could do...
const someFunction = x => _.flow(g, f(x))(x);
I think this would work as f(x)
would pass x
into f
to get the function out. And then this _.flow(g, f(x))(x)
would pass x
into g
and then pass the output of that into the resulting curried function returned from f
.
It's still clunky though. Not entirely happy with it. Is there another more elegant/more readable way of doing it that could be suggested.