Skip to content

Instantly share code, notes, and snippets.

@Debdut
Last active August 3, 2020 00:44
Show Gist options
  • Save Debdut/9646086d1a402092c7b6a3a083fcd622 to your computer and use it in GitHub Desktop.
Save Debdut/9646086d1a402092c7b6a3a083fcd622 to your computer and use it in GitHub Desktop.
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)()
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