Last active
May 4, 2018 19:50
-
-
Save venil7/2a58cce487d95a90a0c9960a894d695b to your computer and use it in GitHub Desktop.
Unlimited arity curried computation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const aux = (f: (a,b) => number, acc: number) => | |
(n?: number) => (n !== undefined) ? aux(f, f(acc, n)) : acc; | |
const add = (a, b) => a + b; | |
const mul = (a, b) => a * b; | |
const sum = aux(add, 0); | |
const product = aux(mul, 1); | |
const sum1 = sum(2)(3)(5)(); //10 | |
const prod1 = product(2)(3)(5)(); // 30 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment