Skip to content

Instantly share code, notes, and snippets.

@UserGalileo
Last active April 14, 2020 19:07
Show Gist options
  • Save UserGalileo/78467948813c635a37dfaa1f8eb27d6b to your computer and use it in GitHub Desktop.
Save UserGalileo/78467948813c635a37dfaa1f8eb27d6b to your computer and use it in GitHub Desktop.
Extracting Composition
// Pointfree utility for "chain"
const chain = fn => a => a.chain(fn);
// generic composition operation
const op = (f1, f2) => compose(chain(f2), f1)
// just to demonstrate, here's the non-generic way of composing our two functions
const op2 = compose(chain(g), f);
// Now we can compose our functions!
const f_g = op(f, g);
// Let's get the result!
const result = f_g('a');
// Identity(a12)
inspect(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment