On Sun, May 24, 2020 at 06:31:46PM -0400, David Mertz wrote:
> I think one thing that pulls in different directions is that both
> composition and piping are useful, and do something closely related. But
> in one the data "goes" forward and in the other the data "goes backward."
The same rule applies to function application though.
> I use bash a lot, and writing something like this is common:
>
> cat data | sort | cut -d; -f6 | grep ^foo | sort -r | uniq -c
And today's "Useless Use Of cat Award" goes to... :-)
sort data | ...
(What is it specifically about cat that is so attractive? I almost
certainly would have done exactly what you did, even knowing that sort
will take a file argument.)
> My data is moving left to right through the operations. In contrast, I
> might write in some hypothetical programming language:
>
> myfilter = uniq[count] ∘ sort[reverse] ∘ grep[^foo] ∘ cut[;,f6] ∘ sort
> result = myfilter(data)
Compared to the regular old function call syntax:
uniq(sort(grep(cut(sort(data)))))
(ignoring extra arguments) where the data still moves right to left.
On the third hand, even if your language doesn't have pipes, it may have
methods:
data.sort().cut().grep().sort().uniq()
which now moves left to right again.
--
Steven
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/QNW2ARA4VEYE4KAQ35OR53JKTKVYDPBF/
Code of Conduct: http://python.org/psf/codeofconduct/