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

[Possible improvement] Auto reset projections? #109

Open
b-enoit-be opened this issue Sep 3, 2022 · 0 comments
Open

[Possible improvement] Auto reset projections? #109

b-enoit-be opened this issue Sep 3, 2022 · 0 comments

Comments

@b-enoit-be
Copy link

b-enoit-be commented Sep 3, 2022

While writing the issue #108, I was wondering if an improvement shouldn't be to systematically reset projections.


Little background: I came to JMESPath thanks to its usage In Ansible. Ansible uses Jinja2, which, previously, would return Python generator from filters like map or select. Because of that, if you needed to display a mapped of filtered list, you would have to explicitly cast it back as list, with a list filter.

e.g.

[1, 2, 3, 4] | select('odd') # gives you a generator object <generator object-id...>

versus

[1, 2, 3, 4] | select('odd') | list # gives you the list [1, 3]

Recently, Jinja decided to change that and those filters return you a list right away, so you can finally do:

[1, 2, 3, 4] | select('odd') # gives you the expected list [1, 3]

I am mostly asking this because I don't see any advantage to have a projection returned.

One downside, though is that on the pipe expression, and if we have string slicing, which will be in the next JEP, we will end up with James, instead of ["J", "J", "J"].

But shouldn't this be handled by parenthesis instead of a pipe expression (which works already!)?

people[*].first[0] # gives `["J", "J", "J"]`
(people[*].first)[0] # gives `James`

Possibly what could make it clearer would be to force parenthesis for the first behaviour?

people[*].(first[0]) # gives `["J", "J", "J"]`
(people[*].first)[0] # gives `James`
people[*].first[0] 
## yields any sort of error, about an ambiguous notation, 
## or return an opinionated or backward compatible solution of the two above?

What are your thoughts?

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

No branches or pull requests

1 participant