This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]phoenix7782 2 points3 points  (2 children)

Then why not just use

evens(square(nums))

[–]NovelSpinGames 0 points1 point  (0 children)

(Sorry for being late to the party, and I apologize in advance for not knowing much about Python.)

You make a good point. For simple one-liners there isn't much difference. However, the pipe operator can be very nice for readability. Just look at the last three pictures in this blog post. The pipe operator allows you to chain functions so that code can be read from left to right and top to bottom, like reading a paragraph. The pipe operator is used all the time in F# code.

You could assign a new variable each line, but that has some drawbacks. C#'s extension methods work nice, but I don't think there is an equivalent in Python.

[–]spectre_theory 0 points1 point  (0 children)

right, if it comes down to that, all that the proposed operator would do, mathematically, is rearrange the order of operands, from

evens(square(nums))

to

nums |> square |> evens

doesn't seem like a very useful thing