-
Notifications
You must be signed in to change notification settings - Fork 79
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
Patterns in variable bindings. #218
Conversation
Impressive work! and i had no idea jq supported combining key/value pattern like |
Regarding
For these reasons, I would also strongly recommend against using this syntax. |
There is also yet another reason why I believe that We could come up with some syntax such as
to solve this problem. In particular, wherever we can write a pattern, we should be able to write That would subsume the
Speaking as somebody who just implemented destructuring in jaq a few days ago, I think that such a syntax should be quite feasible to implement. And speaking as somebody who is trying to rewrite the jq manual, I think that such a syntax should be also relatively easy to describe, teach, and understand. |
While I also think that such syntax could be nice, I think that especially the second idea, namely the |
This PR adds support for patterns in variable bindings, e.g.
. as {a: [$x, {("b", "c"): $y, $z}]} | $x, $y, $z
.This also works in
foreach
andreduce
.Compared to jq, this also allows indexing with integers, e.g.
{(0): $x, (1): $y}
, which is equivalent to[$x, $y]
. This can be useful if you wish to destructure arrays, but not necessarily the starting items.However, jaq does not support the (undocumented) syntax
{$x: ...}
; for example, the filter{x: [1]} as {$x: [$y]} | $x, $y
this yields[1]
and1
in jq.