Functional composition in python

Audric Schiltknecht storm at chemicalstorm.org
Sun Aug 29 17:57:18 EDT 2010


Le 29/08/2010 04:54, Dmitry Groshev a écrit :
> On Aug 29, 5:14 am, Steven D'Aprano<st... at REMOVE-THIS-
> cybersource.com.au>  wrote:
>> On Sat, 28 Aug 2010 21:30:39 +0400, Dmitry Groshev wrote:
>>> Hello all. Some time ago I wrote a little library:
>>> http://github.com/si14/python-functional-composition/, inspired by
>>> modern functional languages like F#. In my opinion it is quite useful
>>> now, but I would like to discuss it.
>>> An example of usage:
[snip]
>
> Generally, f1>>  f2 means "lambda x: f2(f1(x))" or "pass the result of
> f1 to f2". But in python function can return only one value, so a
> composable function should be a function of one argument.

You can use a tuple to return more than just one value:

def f(a,b):
     return (a,b)

 >>> f(1,2)
(1,2)


Ok, technically, it is ONE value, but since you can access any member of 
this tuple :)



More information about the Python-list mailing list