[Python-ideas] Adding a pipe function to functools

Wes Turner wes.turner at gmail.com
Fri Apr 15 14:51:45 EDT 2016


On Apr 15, 2016 9:51 AM, "Ed Minnix" <egregius313 at 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.html

... Sarge also has `|` within command strings for command pipelines
http://sarge.readthedocs.org/en/latest/tutorial.html#creating-command-pipelines

... 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 at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160415/67cd8003/attachment.html>


More information about the Python-ideas mailing list