[issue13430] Add a curry function to the functools module

2011-11-19 Thread Collin Winter
Collin Winter added the comment: I assume I was added to this thread since I wrote the functional module, so I'll give my take in that capacity. IMO Python doesn't need a more general version of partial(); indeed, I question the need for partial() as it is today. Querying Google Code Search f

[issue13430] Add a curry function to the functools module

2011-11-19 Thread Petri Lehtinen
Petri Lehtinen added the comment: @markonervo: Have you tried the pointfree library: http://pypi.python.org/pypi/pointfree/ ? I think it's exactly what you're asking for. The only case I've ever needed currying was managing callback soup in async code. And even then, functools.partial() was

[issue13430] Add a curry function to the functools module

2011-11-18 Thread Marko Nervo
Marko Nervo added the comment: > You will have to try a bit > harder and showcase examples of *useful* code that are made > significantly easier through the use of curry(). Curry is a more advanced functools.partial. So, it could be used *at least* as partial, but it is more powerfull, usable

[issue13430] Add a curry function to the functools module

2011-11-18 Thread Antoine Pitrou
Antoine Pitrou added the comment: > Sure, it's common `defining new functions on other functions`... more > times. Here a stupid example with fold (our reduce). > > @curry > def fold(function, start, sequence): > if len(sequence) == 0: > return start > else: > return fol

[issue13430] Add a curry function to the functools module

2011-11-18 Thread Marko Nervo
Marko Nervo added the comment: > But so does functools.partial. So the question is, what use case does it > help that functools.partial doesn't? Sure, it's common `defining new functions on other functions`... more times. Here a stupid example with fold (our reduce). @curry def fold(function

[issue13430] Add a curry function to the functools module

2011-11-18 Thread Ezio Melotti
Ezio Melotti added the comment: In that thread Guido said: """ Haskell has this too, perhaps even more extreme: there's not really such a thing in Haskell as a function of N arguments (N > 1). "f a b = ..." defines a function f of one argument a which returns another function ("f a") of one argu

[issue13430] Add a curry function to the functools module

2011-11-18 Thread Antoine Pitrou
Antoine Pitrou added the comment: > However, here an example less confusional > > >>> adder = curry(lambda (x, y): (x + y)) > >>> adder3 = adder(3) > >>> adder3(4) > 7 > >>> adder3(5) > 8 > > Currying let you defining new functions on other functions. But so does functools.partial. So the que

[issue13430] Add a curry function to the functools module

2011-11-18 Thread Marko Nervo
Marko Nervo added the comment: I totally disagree with the syntax for curried function, but I think a curry function is perfect for the functools module and I also think it could be useful at least as functools.partial. In addition, a lot of languages support currying, such as Haskell, Scala,

[issue13430] Add a curry function to the functools module

2011-11-18 Thread Ezio Melotti
Ezio Melotti added the comment: FWIW there is a somewhat related thread that proposed a new syntax for curried functions: http://mail.python.org/pipermail/python-ideas/2009-March/003220.html -- stage: -> committed/rejected ___ Python tracker

[issue13430] Add a curry function to the functools module

2011-11-18 Thread Éric Araujo
Éric Araujo added the comment: To go back to your original message: > I think it would be very usefull to add a curry function to the functools > module. For what use cases? > Curried functions could be used as follow. >>> adder(2, 3, 4) >>> adder(2, 3)(4) >>> adder(2)(3)(4) >>> adder(z = 4)

[issue13430] Add a curry function to the functools module

2011-11-18 Thread Marko Nervo
Marko Nervo added the comment: In [1]: import functools In [2]: def adder(x, y, z): ...: return (x + y + z) ...: In [3]: adder = functools.partial(adder) In [4]: adder(2)(3)(4) --- TypeError

[issue13430] Add a curry function to the functools module

2011-11-18 Thread Alex Gaynor
Alex Gaynor added the comment: This already exists, as functools.partial: http://docs.python.org/library/functools.html#functools.partial -- nosy: +alex resolution: -> invalid status: open -> closed ___ Python tracker

[issue13430] Add a curry function to the functools module

2011-11-18 Thread Antoine Pitrou
Antoine Pitrou added the comment: You can use functools.partial for similar effect. Not sure what a dedicated curry() primitive would improve. -- nosy: +pitrou ___ Python tracker _

[issue13430] Add a curry function to the functools module

2011-11-18 Thread Ezio Melotti
Ezio Melotti added the comment: This sounds similar to http://wiki.python.org/moin/PythonDecoratorLibrary#Pseudo-currying Do you have a concrete use case for this? -- nosy: +ezio.melotti versions: +Python 3.3 -Python 2.7, Python 3.4 ___ Python trac

[issue13430] Add a curry function to the functools module

2011-11-18 Thread Marko Nervo
New submission from Marko Nervo : I think it would be very usefull to add a curry function to the functools module. It should be like this. def curry(func, *args, **kwargs): if (len(args) + len(kwargs)) >= func.__code__.co_argcount: return func(*args, **kwargs) return (lambd