Skip to content

Instantly share code, notes, and snippets.

@audinue
Last active December 9, 2020 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save audinue/005a5dee384e8afcd044fb2ab40a9f81 to your computer and use it in GitHub Desktop.
Save audinue/005a5dee384e8afcd044fb2ab40a9f81 to your computer and use it in GitHub Desktop.
Tiny curry with placeholder support.
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}
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