3 ms·
No, if importing something was enough it would be fine. It's more that how a lambda can only contain a single expression means you need to split and name things
by matsemann 3y ago
No, if importing something was enough it would be fine. It's more that how a lambda can only contain a single expression means you need to split and name things everywhere, how you can't pipe/chain things means you need to have intermediate variables or an ungodly amount of nesting etc. Yeah, technically feasible, but it's not "pythonic" so you solve it some other (to me) less elegant way.
- bPspGiJT8Y 3y ago> It's more that how a lambda can only contain a single expression That's exactly how lambdas (and all functions) work in actually functional languages like Haskell. And it's a good thing,lambdas shouldn't allow statements. > how you can't pipe/chain things Ironically after switching from Elixir to a language where I can have any operator I wish, I found myself using the equivalent of Elixir's |> only on a very rare occasion. IMO they're vastly overrated.
- matsemann 3y agoHmm, you can surely use multiple lets in a lambda in haskell, as in every other function? And it doesn't have to be the pipe operator, just something similar. Like list.map().filter().reduce() instead of reduce(filter(map(list))) which quickly gets unwindly.
- boxed 3y ago> need to split and name things everywhere It can sometimes be annoying yes, but when you come back to the code 6 months later it's mostly a good thing.
- matsemann 3y agoBut in other languages it's clear what the code is doing. If you have a chain of map, filters and other operations, they are all named and easy to grok. In a python list comprehension a lot of things will be going on, without named parts. So then you need to name stuff to keep track. So you got foo, then foo_filtered, then foo_sorted, then foo_grouped. And that doesn't really convey anything more than in a language where you would do foo.filter().sort().group().