Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative object comprehension syntax #139

Open
marcelocantos opened this issue Nov 16, 2023 · 1 comment
Open

Alternative object comprehension syntax #139

marcelocantos opened this issue Nov 16, 2023 · 1 comment
Assignees
Labels
call-for-discussion The suggestion requires further discussion on its design

Comments

@marcelocantos
Copy link

marcelocantos commented Nov 16, 2023

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:

  1. Perhaps for [k]: v in o is better, since k is a variable, not a literal field name.
  2. This syntax might allow order-preservation via for k: v preserve_order in {b: 1, a: 2}.
@JarvisCraft JarvisCraft added enhancement New feature or request call-for-discussion The suggestion requires further discussion on its design and removed enhancement New feature or request labels Nov 17, 2023
@CertainLach
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
call-for-discussion The suggestion requires further discussion on its design
Projects
None yet
Development

No branches or pull requests

3 participants