In a comprehension, the flattening happens by supporting multiple generators. I don’t think we need to introduce another way of flattening, especially because the way comprehensions currently flatten also allow you to filter easily. And this adds an even bigger departure from the regular for
(as in the most common case we now need to wrap each of the collection’s element in a list).
The proposal also explains why it is beneficial to have the variables declared before the generators, as it gives us more power to express other constructs later on.
I strongly disagree with this version. If I were to read such code, I would expect count and sum to be reset on every new value of i
.
To be honest, I would say “having to read perfectly in english” is a red herring. I understand the current syntax can be confusing for some (and there is criticism saying so), but optimizing for “english readability” is not what we should aim for to address it.
The proposal also explains why it is beneficial to declare the “let” variables early on, as that gives the ability to express more complex scenarios in the future.