Yeah, I'm not sure how `[action] for [variable] in...
# language-proposals
k
Yeah, I'm not sure how
[action] for [variable] in [collection]
is more readable than
[collection].map { [variable] -> [action] }
. The latter reads left to right perfectly. For the former, you need to read the whole thing to get context on any of it. And it requires special syntax
4
g
Agree, comperhension always blew my mind in Python. But solution with map creates a copy of collection, but it can be solved by compiler intrinsic or just with collection builder without special syntax
j
Kotlins extension and chaining syntax is the best I have seen. I hope it doenst change
k
Agreed, I'm no expert on compilers (in fact, I'd say I know very little about them) but my guess is that building an intrinsic for
map
might be simpler than adding an entirely new syntax to the language for comprehensions
And yes, I also agree, the fact that "comprehension"-like operations in Kotlin chain so well and read perfectly from left to right is one of the best features of the language. It's incredibly clear what's happening when you see
foo.filter { ... }.map { ... }
d
I generally agree that I’m not sure for comprehensions would fit well with the rest of the language, however if someone showed up with some good use cases to justify the complexity and the addition of yet another way to iterate over lists I could change my mind.
c
Agreed. Python’s comprehensions can’t compose and are much more verbose. A mishmash of various concepts wrapped in a bad syntax. Python in a nutshell.
3