flowRight
is a function from the lodash library that allows you to compose functions from right to left. This means the arguments passed to the function are passed through a series of other functions in order, with the value returned by the last function being the final output.
Here's an example of how to use flowRight
:
221 chars10 lines
In this example, we're creating three functions (add
, square
, and double
) and then using flowRight
to combine them into a single function. When we call this combined function with the arguments 1
and 2
, the steps are as follows:
double(1, 2)
returns 3
add(3)
returns a new function waiting for the 2nd parameter to be supplied to itsquare(3, 2)
returns 9
9
.As you can see, flowRight
is a powerful tool for composing complex functionality and can help keep your code organized and readable.
gistlibby LogSnag