Last active
November 6, 2022 07:35
-
-
Save gordonbrander/439514c44cb223f69c32b40b42b4bab2 to your computer and use it in GitHub Desktop.
rest - decorate functions so you can bind "rest" arguments with f.rest().
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
// 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