3 ms·
That's because in Python comprehensions have better ergonomics than lambdas. Scala has comprehensions too for { i <- 1 to 10; if i % 2 == 0 } yield i but so
by erik_seaberg 6y ago
That's because in Python comprehensions have better ergonomics than lambdas. Scala has comprehensions too
for { i <- 1 to 10; if i % 2 == 0 } yield i
but sometimes lambdas can be cleaner
1 to 10 filter { _ % 2 == 0 }
- throwaway894345 6y agoThe limitation to lambdas is just the single expression, but the same limitation exists for comprehensions. Comprehensions aren’t particularly readable beyond one loop and a condition or so (I say this begrudgingly as someone who likes to craft complex comprehensions). Beyond that for loops are encouraged, not filter() and friends, which suggests that they are perhaps not as amazing as some in this thread suggest.