What does HackerNews think of Pipe?
A Python library to use infix notation in Python
Language:
Python
Python doesn't have a built-in pipe operator, but that doesn't mean you can't do it. The pipe [1] library is popular.
is_even = where(lambda x: x % 2 == 0)
sum(fib() | is_even | take_while(lambda x: x < 4000000)
The Apache Beam SDK for Python is another example. It has its own pipe expressions (|, >>, |>, etc.).I'm not sure if you are aware, but there are several efforts out there to give Python a more data-pipeline-friendly (composable pipe) syntax:
1) Coconut: http://coconut-lang.org/
2) https://github.com/JulienPalard/Pipe
3) Pandas also has a new dataframe pipe method. https://pandas.pydata.org/pandas-docs/stable/generated/panda...
I would look at those before rolling out a custom solution.
Also https://github.com/JulienPalard/Pipe
Though I think there are a few generator based libs like this. I think the style is called "flow programming"?
Does anyone know where "Collection Pipeline" comes from? Did Martin coin this term?
There's a Python lib that implements it: https://github.com/JulienPalard/Pipe
> Try to write "find . -name '.py' | xargs cat | wc -l" in other languages.
import pipe\n find(name='*.py') | xargs(cat) | wc().lines\n
\nThe implementation of the functions is left as an exercise for the reader, but the syntax is valid.Reminds me of something I saw not too long ago...
https://github.com/JulienPalard/Pipe
It would be really cool (though admittedly less Pythonic) to combine the infix notation provided by the Pipe library to allow more shell-like function chaining.
Instead of this...
print wc(ls("/etc", "-1"), "-l")
You would have this... print ls("/etc", "-1") | wc("-l")