compose()
compose<
Fns>(...fns): (...args) =>ComposeReturn<Fns>
Allows you combine two or more functions to create a new function, which passes the results from one function to the next until all have be called. Has a right-to-left call order.
Type Parameters
Fns
Fns extends CompositionArray
The list of unary functions.
Parameters
fns
...Composable<Fns>
The functions to compose.
Returns
(...
args):ComposeReturn<Fns>
Parameters
args
...ComposeParams<Fns>
Returns
ComposeReturn<Fns>
Remarks
The implementation follows right-to-left composition semantics:
- The rightmost function is applied first to the input arguments
- Each subsequent function (moving left) receives the result of the previous function
- The leftmost function's result becomes the final output
Example
const getActiveUsers = compose(
displayPage,
sortUserNames,
filterActive,
);
const activeUsers = getActiveUsersByPage(users);