xen-orchestra/@vates/compose/USAGE.md

34 lines
478 B
Markdown
Raw Normal View History

```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])
```
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]
)
```