Skip to content

Commit

Permalink
Introduce variadic _compose_ in ch05 and fallback to simple _compose2…
Browse files Browse the repository at this point in the history
…_ for reasonning

Close #443
Close #447
  • Loading branch information
KtorZ committed May 24, 2018
1 parent afdc710 commit 2c8dece
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ch05.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@
Here's `compose`:

```js
const compose = (f, g) => x => f(g(x));
const compose = (...fns) => (...args) => fns.reduceRight((res, fn) => [fn.call(null, ...res)], args)[0];
```

... Don't be scared! This is the level-9000-super-Saiyan-form of _compose_. For the sake of reasoning, let's drop the variadic implementation and consider a simpler form that can compose two functions together. Once you get your head around that, you can push the abstraction further and consider it simply works for any number of functions (we could even prove that)!
Here's a more friendly _compose_ for you my dear readers:

```js
const compose2 = (f, g) => x => f(g(x));
```

`f` and `g` are functions and `x` is the value being "piped" through them.
Expand Down

0 comments on commit 2c8dece

Please sign in to comment.