Manual references `find` function that doesn't exist
Describe the bug
The manual references a find function as something that's defined in jq but no such function exists.
To Reproduce
Run man jq. In the "ADVANCED FEATURES" section it says
It is also possible to define functions in jq, although this is is a feature whose biggest use is defining jq's standard library (many jq functions such as
mapandfindare in fact written in jq).
Expected behavior
Such a function should in fact exist. I might expect usage to look like find(condition), find(generator; condition), where the former takes an array as input and the latter operates on a generator.
I'd also like a find_last variant so that way I don't have to do something like [generator] | reverse | find(cond).
Alternatively, the reference to find in the manual could just be replaced with a different function, but find seems useful enough to actually provide directly.
Environment (please complete the following information):
- OS and Version: macOS 12.1 (21C52)
- jq version 1.6
Hi again, I get a feeling it's suppose to say select? anyway, so something similar to:
def find(g; c): first(g | select(c));
def find(c): find(.[]; c);
def find_last(g; c): last(g | select(c));
def find_last(c): find_last(.[]; c);
?
You may be right about select, it does appear to be written in native jq.
As for your definitions, they look right to me, though I wonder if find_last/1 would be faster if done like find(reverse[]; c), as last() actually needs to process every item from the beginning. I don't know for sure that find(reverse[]; c) would be faster, but it certainly seems like it should be possible for jq to avoid constructing the actual reversed array (if it doesn't do that optimization, then maybe inlining the definition of reverse would?)
#1898, #1962