Function composition in Javascript and Elixir

Function composition in Javascript and Elixir

Function composition is a programming technique that could be very useful and very expressive at the same time.
Essentially it consists to combine N simple (unary and hopefully pure) functions making the output of a function being the input for another one.

To make working function composition in Javascript we need to extend the Function object with a polyfill (inspired by this great book):

That one produces:“English course lesson 1: the lazy dog jumps over the quick brown fox”

Why?
Because the compose polyfill works from right to the left. The last function on the right will be the first applied.
Here is the the more natural (for western people, at least) version of compose: the sequence polyfill, from left to right:

That one produces:“English course lesson 1: the quick brown jumps over fox the lazy dog”

Besides the order of function application, I think the interesting thing of this approach, and the functional programming in general, is to produce efficient and readable code based on the smallest possible chunks, Unix style.
That improves decoupling and bug fixing.

And… regarding readability, just one word: Elixir!

In Elixir is not needed a polyfill because the function composition is built-in in the language, via the wonderful Elixir Pipe operator: “|>”