@mqschwanda/compose

0.0.1 • Public • Published

compose

compose(...functions)

Composes functions from right to left.

This is a functional programming utility, and is included in Redux as a convenience.
You might want to use it to apply several functions in a row.

Arguments

  1. (arguments): The functions to compose. Each function is expected to accept a single parameter. Its return value will be provided as an argument to the function standing to the left, and so on. The exception is the right-most argument which can accept multiple parameters, as it will provide the signature for the resulting composed function.

Returns

(Function): The final function obtained by composing the given functions from right to left.

Example

This example demonstrates how to use compose to enhance a store with applyMiddleware and a few developer tools from the redux-devtools package.

import compose from '@mqschwanda/compose';
import { connect } from 'redux'; // redux connect container
import passthrough from 'react-passthrough'; // react passthrough container

const container = compose(
  connect((store) => ({ store })),
  passthrough({ omit: ['dispatch'] }),
);

Tips

  • All compose does is let you write deeply nested function transformations without the rightward drift of the code. Don't give it too much credit!

Readme

Keywords

Package Sidebar

Install

npm i @mqschwanda/compose

Weekly Downloads

1

Version

0.0.1

License

MIT

Unpacked Size

4.07 kB

Total Files

10

Last publish

Collaborators

  • mqschwanda