-
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
Fix manual on paths/1 to use boolean filter for its argument #2678
Conversation
`paths(f)` outputs the paths to any values for which `f` is true. | ||
That is, `paths(numbers)` outputs the paths to all numeric | ||
`paths(f)` outputs the paths to any values for which `f` is `true`. | ||
That is, `paths(type == "number")` outputs the paths to all numeric |
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.
This got me thinking that i several times wanted to have is_number
etc functions, for fq i have these https://github.com/wader/fq/blob/d15a41f9430f869dc6d11ac360f56c29e3a1b45e/pkg/interp/internal.jq#L147C1-L153 because i kept needing it
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.
def paths(node_filter): . as $dot|paths|select(. as $p|$dot|getpath($p)|node_filter);
f
doesn't have to output true
-- it just has to not be empty
or null
.
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 mean, maybe that's a bug...
But separately from that, jq considers any non-null, non-empty [EDIT: and non-false
] value to be "trueish".
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.
and non-false. :^)
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.
Also empty is not really a falsish value, it really stops execution for that expression. e.g. if empty then "yes" else "no" end
outputs nothing, not "no"
. Anyway, this is all intended in my opinion. false
and null
are the only false values, and empty
works as it should, and when you use it inside select()
it is effectively the same as false.
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.
As a user manual, it is enough to mention that the filter works well with boolean filter arguments. No need to mention all its behaviors.
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.
Yes, speaking of "empty values" is not exactly accurate. It's a bit of a colloquialism in jq speak. In the context of select/1
though, empty
really is falseish :)
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.
@wader I'm not sure that it's a good idea to document all the places where trueish values work, yeah.
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.
@nicowilliams true :)
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.
ish
Thanks! |
The manual of
paths/1
explains its usage the argument filter yields a boolean. Nevertheless the following sentence uses non-boolean filternumbers
and also the definition ofleaf_paths
filter was wrong (#1163). The filterleaf_paths
was deprecated 9 years ago and was removed in #2666. There is still remaining confusing manual so I fixed it in this PR. Along with #2666, this PR resolves #2288.