2021-02-18 03:38:32 -06:00
|
|
|
```js
|
|
|
|
import { compose } from '@vates/compose'
|
|
|
|
|
|
|
|
const add2 = x => x + 2
|
|
|
|
const mul3 = x => x * 3
|
|
|
|
|
|
|
|
// const f = x => mul3(add2(x))
|
|
|
|
const f = compose(add2, mul3)
|
|
|
|
|
|
|
|
console.log(f(5))
|
|
|
|
// → 21
|
|
|
|
```
|
2021-02-18 04:19:41 -06:00
|
|
|
|
|
|
|
Functions may also be passed in an array:
|
|
|
|
|
|
|
|
```js
|
|
|
|
const f = compose([add2, mul3])
|
|
|
|
```
|
2021-02-18 04:24:39 -06:00
|
|
|
|
|
|
|
Options can be passed as first parameters:
|
|
|
|
|
|
|
|
```js
|
|
|
|
const f = compose(
|
|
|
|
{
|
2021-02-18 04:25:00 -06:00
|
|
|
// compose async functions
|
|
|
|
async: true,
|
|
|
|
|
2021-02-18 04:24:39 -06:00
|
|
|
// compose from right to left
|
|
|
|
right: true,
|
|
|
|
},
|
|
|
|
[add2, mul3]
|
|
|
|
)
|
|
|
|
```
|