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

[feature request]: allow iterating over object in comprension (like dict comprehension in python) #865

Open
bendavis78 opened this issue Nov 28, 2020 · 1 comment

Comments

@bendavis78
Copy link

It would be useful to be able to do something like dict comprehensions in python, eg: for key, value in obj

A use-case would be when defining environment variables for a kubernetes container like so:

{
  env:: {
    FOO: 'foo',
    BAR: 'bar',
    BAZ: 'baz'
  },
  containerEnv: [{name: k, value: v} for k, v in $.env]
}

->

{"containerEnv": [
  {"name": "FOO", "value": "foo"},
  {"name": "BAR", "value": "bar"},
  {"name": "BAZ", "value": "baz"}
]}
@sbarzowski
Copy link
Collaborator

You can do this currently with std.objectFields/std.objectFieldsAll. See also: #543.

Maybe we could add a shorthand syntax for that like in your example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants