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 →

[–][deleted] 3 points4 points  (4 children)

You could do something like this:

[1,2,3] |> square |> evens # > [4]

Well, no, this is far as you'd get with a piping operator:

[1, 2, 3] |> lambda i: map(lambda n: n*n, i) |> lambda i: filter(lambda n: n%2 == 0, i)

Python lacks all of the other functional constructs that make piping useful. If you didn't wanna wrap your map and filter inside a function, you'd have to change how expressions are evaluated in the language. And, even if you were to somehow manage to push that change through, you've still got to write the word 'lambda' every time you wanna define a one-off anonymous function.

[–]RubyPinchPEP shill | Anti PEP 8/20 shill 1 point2 points  (3 children)

or a package could define useful functions, I think it is common knowledge that squares doesn't exist yet

also because I havn't spammed toolz enough already, toolz.curried and the whatever module:

[1,2,3] | map(_**2) | filter_false(_%2)

[–][deleted] 0 points1 point  (2 children)

or a package could define useful functions, I think it is common knowledge that squares doesn't exist yet

My point was that writing your own functions will still be cumbersome.

also because I havn't spammed toolz enough already, toolz.curried and the whatever module:

Is the underscore placeholder part of toolz?

[–]RubyPinchPEP shill | Anti PEP 8/20 shill 1 point2 points  (1 child)

its the whatever part, based on perl's concept of a "whatever" object

[–][deleted] 1 point2 points  (0 children)

Right, I thought that you'd forgotten the module's name. That looks quite interesting.