Skip to content

Commit 88f01a7

Browse files
authored
simplify paths/0 and paths/1
`recurse/0` already handles traversing objects and arrays, so it is more consistent to use that. For `paths/1` it is easier to use the actual value returned by `recurse` instead of querying that value with `getpath/1` afterwards.
1 parent 6c03513 commit 88f01a7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/builtin.jq

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ def indices($i): if type == "array" and ($i|type) == "array" then .[$i]
4848
else .[$i] end;
4949
def index($i): indices($i) | .[0]; # TODO: optimize
5050
def rindex($i): indices($i) | .[-1:][0]; # TODO: optimize
51-
def paths: path(recurse(if (type|. == "array" or . == "object") then .[] else empty end))|select(length > 0);
52-
def paths(node_filter): . as $dot|paths|select(. as $p|$dot|getpath($p)|node_filter);
51+
def paths: path(recurse)|select(length > 0);
52+
def paths(node_filter): path(recurse|select(node_filter))|select(length > 0);
5353
def isfinite: type == "number" and (isinfinite | not);
5454
def arrays: select(type == "array");
5555
def objects: select(type == "object");

0 commit comments

Comments
 (0)