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

Currying increasing arity... #6

Open
hoegrammer opened this issue Sep 16, 2016 · 2 comments
Open

Currying increasing arity... #6

hoegrammer opened this issue Sep 16, 2016 · 2 comments
Assignees
Labels

Comments

@hoegrammer
Copy link

I like this and I'm thinking of using it in my next project but I'm struggling to understand why currying increases arity and whether this is a good idea. Is it taken from another functional language? The only one I am familiar with is Haskell which does not do that.

When I try currying a function with 3 inputs and then increasing the arity, I get strange results:

addAndMult = fjs.curry((x, y, z) => (x + y) * z
addAndMult (2, 6, 3)
24 // as expected: 8 times 3
addAndMult(2, 6, 3, 1)
0 // why?
addAndMult(2, 6, 3, 1, 2)
2 // why?
addAndMult(2, 6, 3, 1, 2, 3)
10 // why?

@leecrossley
Copy link
Member

Extending arity is really designed for an initial 2 defined arguments in your base function, i.e.

fjs.curry((x, y) => { return x + y; });

Imagine it's passing the result back in as the first arg, then the next as the second - like a fold.

I should probably document and implement this better.

@leecrossley leecrossley self-assigned this Dec 20, 2016
@lambdatastic
Copy link

This doesn't really match the mathematical definition of currying. The functionality you've added to is is a combination of unapply and reduce from Ramda. Using that library and the addition function you used above, it would look more like this:

R.unapply(R.reduce((x, y) => (x + y), 0))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants