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

Should _ fail with ArityError, or return a curried function? #7

Open
low-ghost opened this issue Mar 19, 2016 · 6 comments
Open

Should _ fail with ArityError, or return a curried function? #7

low-ghost opened this issue Mar 19, 2016 · 6 comments

Comments

@low-ghost
Copy link

Improperly handling arity can be a hard to track down source of error, especially when composing functions, but I would want (_ + _)(2) to return a function that looked like "(x1) => (2 + x1)" such that (_ + _)(2, 3) and (_ + _)(2)(3) would be equivalent and both result in 5.

I can understand the intent of the TypeError and it could actually be the best approach to ease problems dealing with composition and with standard python functions, e.g.

list(filter(_ < _, [9,10,11]))

would be problematic. However, it might be worth considering the curried behavior.

@jacobbridges
Copy link

What do you think of adding a "curried" submodule to fn.py? Example:

from fn.curried import _

f = (_ + _)
f2 = f(2)
x = f2(3)
x == 5

And when importing from the normal module, it produces an ArityError:

from fn import _

f = (_ + _)
f2 = f(2)

ArityError: (_ + _) expected 2 arguments, got 1

@low-ghost
Copy link
Author

that's definitely a good idea. Doesn't break existing code but gives the curry-all-the-things functional option. I was also thinking _ could be expanded to more operators. In particular I was thinking names = map(_.name, users) would be neat, basically creating a getter for name on whatever dict is sent in. Just now came across a repo that implements it: https://github.com/Suor/whatever. Maybe some interesting ideas on expanding the underscore's capabilities, though it does seem like it leads to a few confusing cases

@jacobbridges
Copy link

Making it easier to create lambda functions is (IMO) always a good thing. If we can incorporate the functionality of the whatever object into fn.py's _ object without backward-incompatible changes, then I think we should go for it.

I will set the milestones for these features to be v1.1.0, to give us enough time to plan and build out this feature.

@jacobbridges jacobbridges modified the milestones: v1.1., v1.1.0 Mar 25, 2016
@jacobbridges
Copy link

Just redoing the milestones, and I noticed that I cannot set a milestone on this yet. If adding the "whatever" functionality to fn.py's _ will incorporate breaking changes, then this feature should be pushed to v1.0.0. But, if we manage to build out this new functionality without breaking changes, we can push this through in a new minor version (e.g. 0.5.0).

@cad106uk
Copy link

Personally I am in favour of having the currying functionality and bumping the the version number.

@Digenis
Copy link
Member

Digenis commented Apr 24, 2016

There are many possible flavours of underscore, with curry being just one of them.
Let's keep the default one as simple as possible
and provide the alternatives under different names.

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

No branches or pull requests

4 participants