Adding a pipe function to functools

Hello,
I have been looking over the toolz library and one of the functions I like the most is pipe. Since most programmers are familiar with piping (via the Unix `|` symbol), and it can help make tighter code, I think it would be nice to add it to the standard library (such as functools).
- Ed Minnix

On Fri, Apr 15, 2016 at 09:41:41AM -0400, Ed Minnix wrote:
Hello,
I have been looking over the toolz library and one of the functions I like the most is pipe. Since most programmers are familiar with piping (via the Unix `|` symbol), and it can help make tighter code, I think it would be nice to add it to the standard library (such as functools).
I don't know the toolz library, but I have this:
http://code.activestate.com/recipes/580625-collection-pipeline-in-python/
Is that the sort of thing you mean?
It's certainly not ready yet for the std lib, but if there's interest in it, I should be able to tidy it up and publish it.

I really like this tool:
https://github.com/JulienPalard/Pipe
It is really a matter of implementing the __or__ operator on iterators. Or possibly, as this module above, add the operator for all functions dealing with iterators as first argument

Hi,
Le 15 avril 2016 19:29:40 GMT+02:00, "João Bernardo" jbvsmo@gmail.com a écrit :
I really like this tool:
First, thank you João !
However I almost don't use it myself, I dislike the idea of exposing an overloaded operator (may cause surprises), and there's in fact a very few places where it's really clearer without reducing maintainability. I mean, working with a long pipe is opaque (no variables involved, so no logging no breakpoints, and no names, well chosen names helps readability).
Also using my Pipe module forces you to mix infix with prefix calls, and I dislike mixing syntaxes, yet having some DSL is sometime cool when they are really useful, think of SQL typically.
Finally the resulting code does clearly not look like Python code, even if readable, it may hurt readability, causing a surprise like "wow what is that, how is it possible ?" Almost forcing one to read Pipe doc instead of simply read Python code ...
All of this obviously also apply to the idea of adding an infix call syntax to the stdlib, so I'm -1 on it.

Hi,
Le 15 avril 2016 15:41:41 GMT+02:00, Ed Minnix egregius313@gmail.com a écrit :
Since most programmers are familiar with piping (via the Unix `|` symbol)
See also: https://mail.python.org/pipermail//python-ideas/2014-October/029839.html

On Apr 15, 2016 9:51 AM, "Ed Minnix" egregius313@gmail.com wrote:
Hello,
I have been looking over the toolz library and one of the functions I
like the most is pipe. Since most programmers are familiar with piping (via the Unix `|` symbol), and it can help make tighter code, I think it would be nice to add it to the standard library (such as functools).
toolz.functoolz.pipe: Docs: http:// http://toolz.readthedocs.org/en/latest/api.html#toolz.functoolz.pipe toolz.readthedocs.org http://toolz.readthedocs.org/en/latest/api.html#toolz.functoolz.pipe /en/latest/ http://toolz.readthedocs.org/en/latest/api.html#toolz.functoolz.pipe api.html# http://toolz.readthedocs.org/en/latest/api.html#toolz.functoolz.pipe toolz.functoolz.pipe http://toolz.readthedocs.org/en/latest/api.html#toolz.functoolz.pipe Src: https://github.com/pytoolz/toolz/blob/master/toolz/functoolz.py
def pipe(data, *funcs): """ [...] """ for func in funcs: data = func(data) return data
`|` is a "vertical bar": https://en.m.wikipedia.org/wiki/Vertical_bar
In Python, | is the 'bitwise or' operator __or__:
* [ ] the operator. docs seem to omit ``|`` #TODO * https://docs.python.org/2/library/operator.html?#operator.__or__ * https://docs.python.org/3/library/operator.html?#operator.__or__ * https://docs.python.org/2/reference/expressions.html#index-63 * http://python-reference.readthedocs.org/en/latest/docs/operators/bitwise_OR....
... Sarge also has `|` within command strings for command pipelines http://sarge.readthedocs.org/en/latest/tutorial.html#creating-command-pipeli...
... functools.compose() & functools.partial()
* https://docs.python.org/3.1/howto/functional.html#the-functional-module
from functional import compose, partial import functools multi_compose = partial(functools.reduce, compose)
* https://docs.python.org/3.5/library/functools.html
* functools.compose is gone!
- Ed Minnix
Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/

On Fri, Apr 15, 2016 at 01:51:45PM -0500, Wes Turner wrote:
https://docs.python.org/3.1/howto/functional.html#the-functional-module
from functional import compose, partial import functools multi_compose = partial(functools.reduce, compose)
https://docs.python.org/3.5/library/functools.html
- functools.compose is gone!
functools.compose never existed. The above example is functional.compose, a third party library.
participants (5)
-
Ed Minnix
-
João Bernardo
-
Julien Palard
-
Steven D'Aprano
-
Wes Turner