Skip to content

Instantly share code, notes, and snippets.

@IsTheJack
Last active February 11, 2018 22:20
Show Gist options
  • Save IsTheJack/6fa883c7d616d3e9e28fc085165355ed to your computer and use it in GitHub Desktop.
Save IsTheJack/6fa883c7d616d3e9e28fc085165355ed to your computer and use it in GitHub Desktop.
// implementando operador de composição (f1 º f2)(value)
const compose2 = (fn1, fn2) => value => fn1(fn2(value));
// Criando duas funções puras
const increment = (n) => n + 1;
const double = (n) => n * 2;
// Compondo duas funções puras.
const incrementedDouble = compose2(increment, double);
// Output
incrementedDouble(2); // -> 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment