mark shroyer, dot com: this is where I keep my things

Site Navigation


Pointfree style in Python

November 14, 2011 – 6:12 am

I’ve been getting back into Python lately… I just wrote a small module that provides support for pointfree style programming with a combination of automatic partial function/method application and operator overloading for function composition:

>>> from pointfree import *
>>> from operator import add

>>> fn = pfmap(len) \
         >> pfmap(lambda n: n**2) \
         >> pfreduce(add, initial=0)

>>> fn(["foo", "barr", "bazzz"])
50

See the overview for a lengthier introduction. You can install the pointfree module from the Python Package Index:

$ pip install pointfree

Links:

Posted in Code | Leave a reply

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>