Skip to content

Instantly share code, notes, and snippets.

@gordonbrander
Last active November 6, 2022 07:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gordonbrander/439514c44cb223f69c32b40b42b4bab2 to your computer and use it in GitHub Desktop.
Save gordonbrander/439514c44cb223f69c32b40b42b4bab2 to your computer and use it in GitHub Desktop.
rest - decorate functions so you can bind "rest" arguments with f.rest().
// Decorate a function with a method that allows you to bind "rest" args
// (everything except the first argument).
// Usage:
//
// const f = rest((a, b, c) => a + b + c)
// const fbc = f.rest("b", "c")
// fbc("a")
// // "abc"
const rest = f => {
f.rest = (...rest) => v => f(v, ...rest)
return f
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment