Alternative object comprehension syntax
marcelocantos opened this issue · 1 comments
marcelocantos commented
for [k, v] in o
is pretty cool but I was thinking it would be even nicer to have for k: v in o
, which then allows for k:: v in o
to iterate over hidden fields and for k::: v in o
to hit all fields.
I'm happy to have a crack at it if you like the idea but it’s not a priority.
Notes:
- Perhaps
for [k]: v in o
is better, sincek
is a variable, not a literal field name. - This syntax might allow order-preservation via
for k: v preserve_order in {b: 1, a: 2}
.
CertainLach commented
The [k, v]
syntax is not something special made for object comprehension, this is a object deconstruction syntax, which is available in other contexts, i.e
local [a, b] = [1, 2];
The only thing added to comprehension is a semantic change, which allowed iteration over objects, which yields [key, value]
pairs, I'm not sure how I feel about adding special syntax just for that, even if it does allow to implement order preservation here.