Last active
August 3, 2020 00:44
-
-
Save Debdut/9646086d1a402092c7b6a3a083fcd622 to your computer and use it in GitHub Desktop.
This file contains 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
function curry (f) { | |
return function next (a) { | |
return function (b) { | |
if (b) { | |
return next(f(a, b)) | |
} | |
return a | |
} | |
} | |
} | |
function curryLazy (f) { | |
return function next (...a) { | |
return function (b) { | |
if (b) { | |
return next(...a, b) | |
} | |
return a.reduce(f) | |
} | |
} | |
} | |
const add = (a, b) => a+b | |
const curryAdd = curryLazy(add) | |
curryAdd(1)(2)(3)(4)() |
This file contains 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
function curry (f) { | |
const next = a => b => (b === undefined ? a : next(f(a, b))) | |
return next | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment