-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
builtin: add pick(stream) #2656
Conversation
pick(stream) works on both arrays and objects Restrictions on the dot-paths are specified in manual.yml See jqlang#2578
I wonder if it would make sense to extend the object construction syntax to allow things like Sorry for rambling, maybe i should create a proposal issue to collect ideas if it's something we want to consider? ... also i have no idea about implementation difficulty |
@wader - the linked issue already refers to such a proposal, which of course involves an extension to the language, whereas this PR only proposes a builtin, which I think is simple and useful enough to be included regardless of any such extension. |
@pkoppstein Aha, i see. A nice thing with |
src/builtin.jq
Outdated
@@ -260,6 +260,12 @@ def walk(f): | |||
else f | |||
end; | |||
|
|||
# stream should be a stream of dot-paths | |||
def pick(stream): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than call the thunk stream
I'd call it paths
or pathexp
. After all, it's not used as a stream but rather passed to path/1
which then generates a stream of paths.
docs/content/manual/manual.yml
Outdated
@@ -925,6 +925,24 @@ sections: | |||
input: '{"a": 1, "b": 2, "c": 3}' | |||
output: ['{"a": 2, "b": 3, "c": 4}'] | |||
|
|||
- title: "`pick(stream)`" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want s/stream/pathexp/
here and below, since the closure passed here is passed to path/1
, so it's really a path expression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to update the docs to say pathexps
.
Apart from proposing |
@nicowilliams wrote:
How about s/stream/pathexps/ ? I wanted to emphasize the "reduction" aspect of the def, i.e. that the argument is NOT regular. |
Works for me! |
Change the name of the formal parameter.
Change formal parameter name
@nicowilliams - Done. Thanks for reminder. |
Thanks! |
pick(stream) works on both arrays and objects
Restrictions on the dot-paths are specified in manual.yml
See #2578