Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

See how optional parameters and currying could work #13

Open
WaldoJeffers opened this issue May 12, 2018 · 1 comment
Open

See how optional parameters and currying could work #13

WaldoJeffers opened this issue May 12, 2018 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@WaldoJeffers
Copy link
Owner

WaldoJeffers commented May 12, 2018

Currently, as curry checks the number of passed parameters against the function's length property, curried functions can not have optional parameters, which can be frustrating at times.

Ideas

  • use curryN to define the minimum number of required parameters to make the function work. Execute the function as soon as that number has been reached
  • parse the toString() representation of the function to see how many optional parameters there are

Warning

  • additional parameters should only be the last parameters of a function
  • make sure additional parameters are not removed when using the non-curried version
const add = (a, b, c = 3)
curry(add)(1, 2) // should be 6
curry(add)(1, 2, 4) // should be 7
@WaldoJeffers WaldoJeffers added enhancement New feature or request help wanted Extra attention is needed labels May 12, 2018
@WaldoJeffers
Copy link
Owner Author

Interestingly, parameters with default values are not included in the count returned by fn.length

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant