Last active
December 9, 2020 06:46
-
-
Save audinue/005a5dee384e8afcd044fb2ab40a9f81 to your computer and use it in GitHub Desktop.
Tiny curry with placeholder support.
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
let __={},curry=_=>{let r=l=>(...e)=>{let t=l.map(_=>_===__?e.length?e.shift():__:_);return t.some(_=>_===__)?r(t):_.apply(null,t)};return r(Array(_.length).fill(__))};export{__,curry} |
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
let __ = {} | |
let curry = f => { | |
let curried = xs => (...ys) => { | |
let zs = xs.map( | |
x => x === __ | |
? ys.length | |
? ys.shift() | |
: __ | |
: x | |
) | |
return zs.some(x => x === __) | |
? curried(zs) | |
: f.apply(null, zs) | |
} | |
return curried(Array(f.length).fill(__)) | |
} | |
export { __, curry } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment