Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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 }


The 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: