Last active
February 15, 2018 18:45
-
-
Save webbower/6959e406d01081fe015ee62c4a1b467d to your computer and use it in GitHub Desktop.
Tiny, recursive autocurry (https://medium.com/javascript-scene/a-functional-programmers-introduction-to-javascript-composing-software-d670d14ede30)
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 curry = ( | |
f, arr = [] | |
) => (...args) => ( | |
a => a.length === f.length ? | |
f(...a) : | |
curry(f, a) | |
)([...arr, ...args]); | |
// Unbound native-friendly since you can specify arity (typicaly native.length + 1) | |
const curry2 = ( | |
fn, arity = fn.length, arr = [] | |
) => (...args) => ( | |
a => a.length === arity ? | |
fn(...a) : | |
curry2(fn, arity, a) | |
)([...arr, ...args]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment