<p dir="ltr"><br>
On Apr 15, 2016 9:51 AM, "Ed Minnix" <<a href="mailto:egregius313@gmail.com">egregius313@gmail.com</a>> wrote:<br>
><br>
> Hello,<br>
><br>
> 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).</p>
<p dir="ltr">toolz.functoolz.pipe:<br>
Docs: <a href="http://toolz.readthedocs.org/en/latest/api.html#toolz.functoolz.pipe">http://</a><a href="http://toolz.readthedocs.org/en/latest/api.html#toolz.functoolz.pipe">toolz.readthedocs.org</a><a href="http://toolz.readthedocs.org/en/latest/api.html#toolz.functoolz.pipe">/en/latest/</a><a href="http://toolz.readthedocs.org/en/latest/api.html#toolz.functoolz.pipe">api.html#</a><a href="http://toolz.readthedocs.org/en/latest/api.html#toolz.functoolz.pipe">toolz.functoolz.pipe</a><br>
Src: <a href="https://github.com/pytoolz/toolz/blob/master/toolz/functoolz.py">https://github.com/pytoolz/toolz/blob/master/toolz/functoolz.py</a></p>
<p dir="ltr">> def pipe(data, *funcs):<br>
> """ [...] """<br>
> for func in funcs:<br>
> data = func(data)<br>
> return data<br></p>
<p dir="ltr">`|` is a "vertical bar": <a href="https://en.m.wikipedia.org/wiki/Vertical_bar">https://en.m.wikipedia.org/wiki/Vertical_bar</a></p>
<p dir="ltr">In Python, | is the 'bitwise or' operator __or__:</p>
<p dir="ltr">* [ ] the operator. docs seem to omit ``|`` #TODO<br>
* <a href="https://docs.python.org/2/library/operator.html?#operator.__or__">https://docs.python.org/2/library/operator.html?#operator.__or__</a><br>
* <a href="https://docs.python.org/3/library/operator.html?#operator.__or__">https://docs.python.org/3/library/operator.html?#operator.__or__</a><br>
* <a href="https://docs.python.org/2/reference/expressions.html#index-63">https://docs.python.org/2/reference/expressions.html#index-63</a><br>
* <a href="http://python-reference.readthedocs.org/en/latest/docs/operators/bitwise_OR.html">http://python-reference.readthedocs.org/en/latest/docs/operators/bitwise_OR.html</a></p>
<p dir="ltr">... Sarge also has `|` within command strings for command pipelines <a href="http://sarge.readthedocs.org/en/latest/tutorial.html#creating-command-pipelines">http://sarge.readthedocs.org/en/latest/tutorial.html#creating-command-pipelines</a></p>
<p dir="ltr">... functools.compose() & functools.partial()</p>
<p dir="ltr">* <a href="https://docs.python.org/3.1/howto/functional.html#the-functional-module">https://docs.python.org/3.1/howto/functional.html#the-functional-module</a></p>
<p dir="ltr"> from functional import compose, partial<br>
import functools<br>
multi_compose = partial(functools.reduce, compose)</p>
<p dir="ltr">* <a href="https://docs.python.org/3.5/library/functools.html">https://docs.python.org/3.5/library/functools.html</a></p>
<p dir="ltr"> * functools.compose is gone!</p>
<p dir="ltr">><br>
> - Ed Minnix<br>
> _______________________________________________<br>
> Python-ideas mailing list<br>
><a href="mailto:Python-ideas@python.org"> Python-ideas@python.org</a><br>
><a href="https://mail.python.org/mailman/listinfo/python-ideas"> https://mail.python.org/mailman/listinfo/python-ideas</a><br>
> Code of Conduct:<a href="http://python.org/psf/codeofconduct/"> http://python.org/psf/codeofconduct/</a><br>
</p>