34 lines
478 B
Markdown
34 lines
478 B
Markdown
```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
|
|
```
|
|
|
|
Functions may also be passed in an array:
|
|
|
|
```js
|
|
const f = compose([add2, mul3])
|
|
```
|
|
|
|
Options can be passed as first parameters:
|
|
|
|
```js
|
|
const f = compose(
|
|
{
|
|
// compose async functions
|
|
async: true,
|
|
|
|
// compose from right to left
|
|
right: true,
|
|
},
|
|
[add2, mul3]
|
|
)
|
|
```
|