-
Notifications
You must be signed in to change notification settings - Fork 265
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
Make curry
idempotent such that curry(curry(f)) -> curry(f)
#147
Comments
Yeah, I was thinking about how best to do that. I prefer |
Yeah, I considered those options too. I don't want to use Consider the following: @curry
def f(x, y):
return x + y
g = curry(f)
g is f Do we want |
I don't have a strong opinion one way or the other. Both seem like reasonable options. What is your opinion? |
I'm leaning towards unpacking |
Making a separate |
Yeah, both seem reasonable, and both behaviors are of course possible with If How much of an advantage is there for a curried object to return a partial if only one more argument is needed? Having multiple return types muddies the waters a bit. |
The performance increase for using
|
Figured as much, because you wouldn't have bothered with the hassle otherwise. Okay, so lets make |
…Not finished. This includes a significant change to curried objects: they never return `functools.partial` objects. Instead, `Curry` *uses* `partial`. This is because `partial` behaves differently. Let me illustrate: `curry(lambda x, y=0: x+y)(y=2)` is valid. `partial(lambda x, y=0: x+y)(y=2)` returns a TypeError. More documentation and tests are needed. PRs (and comments) are welcome.
I have created a branch to address this issue (https://github.com/eriknw/toolz/tree/curry_class). It is not yet ready, but feedback and PRs are most welcome. The main change is that a curried instance uses I have not performed any benchmarks, and the pickle protocol still needs implemented. |
…#155 pytoolz#159 1. Idempotent such that `curry(curry(f))` is equivalent to `curry(f)`; see pytoolz#147 2. Comparable via equality and hashable based on `func`, `args`, and `keywords`; see pytoolz#159 3. `func`, `args`, and `keywords` attributes are readonly 4. `__name__` and `__doc__` attributes are writable 5. More efficient implementation using `partial`; see pytoolz#150 6. Curried objects never transmogrigy into `partial` objects; see pytoolz#155
Closing. Idempotency implemented in #170 |
This may be done by having a
Curry
class and acurry
function.The text was updated successfully, but these errors were encountered: