Pipes in Python – Infix Syntax for Function Calls

Usually posting nothing more than a simple link is not my style, but this is just really cool.

Pipe: Infix syntax for Python

Here’s some more links…

Python Package Index Page
Github Page

For now this is simply a reminder to myself to play around with this code a bit. At some point in the future I may write up a short post on this.

Here’s a short excerpt from Julien Palard’s post:

Compare the readability of the classical prefix syntax :

sum(select(where(take_while(fib(), lambda x: x < 1000000) lambda x: x % 2), lambda x: x * x))

And the infix syntax :

fib() | take_while(lambda x: x < 1000000)
      | where(lambda x: x % 2)
      | select(lambda x: x * x)
      | sum()

Isn’t the infix syntax more readable?

Advertisements