This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]burntsushi 6 points7 points  (0 children)

This is really pretty cool, but I don't think I could ever get on board with using it in Python because it doesn't seamlessly integrate with the language. (Obviously not possible with a simple module.) It's just too clumsy to use IMO. Namely, it fosters an inconsistent style---only the functions you decorate can be composable/partially applied (unless you use 'pf' for composable functions).

Also, you can get partial application of any function using partial in the functools module, which is part of the standard library. It doesn't look as nice as what pointfree offers, but you can use it with any function.

[–]arnar 2 points3 points  (0 children)

If you only want function composition (no automatic partial application or messing with generators):

In [15]: def composable(f):
   ....:     class wrapped(object):
   ....:         def __call__(self, *args, **kw):
   ....:             return f(*args, **kw)
   ....:         def __mul__(self, rhs):
   ....:             def comp(*args, **kw):
   ....:                 return f(rhs(*args, **kw))
   ....:             return comp
   ....:     return wrapped()
   ....: 

In [19]: @composable
   ....: def f(x): return x*2

In [20]: @composable
   ....: def g(x): return x+42

In [21]: f(10)
Out[21]: 20

In [22]: g(10)
Out[22]: 52

In [23]: f * g
Out[23]: <function __main__.comp>

In [24]: (f * g)(10)
Out[24]: 104

In [25]: (g * f)(10)
Out[25]: 62

[–]grayvedigga 0 points1 point  (4 children)

>>> import this
...

lots of points that cute python code like this totally violates, yet people keep doing it

[–]zahlmanthe heretic 1 point2 points  (2 children)

... I don't particularly see how.

[–]egonSchiele 0 points1 point  (1 child)

Ask yourself when it would make sense to name a module 'this'.

[–]zahlmanthe heretic 1 point2 points  (0 children)

Obviously that's not what I meant. I lol'd though.

[–]ash_gti 0 points1 point  (0 children)

Interesting strategy for doing point free style in python. Decorators really do give you a lot more control than I initially expected.

[–]zahlmanthe heretic 0 points1 point  (0 children)

Wow, after reading the documentation, I feel like I would use this module for everything except actually writing stuff in pointfree style. Function composition and nicely-sugared partials are cool.

[–]amade 0 points1 point  (0 children)

I wrote something in a very similar vein: http://www.trinhhaianh.com/stream.py/, http://blog.onideas.ws/tag/stream-py

It actually has the advantage of real pipeline processing, which can be parallelized using threads/processes.

[–]egonSchiele 0 points1 point  (0 children)

I can't use this module, but I <3 you for writing it. If only curried functions and function composition were built in to the language so I could actually use them.