Skip to content
Myr

simplify paths/0 and paths/1

Before adoption: this commit came in with the history the project adopted, so no landing records it.

`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.

authored by Andreas Heiduk · committed by GitHub · parent 6c03513 · Browse files · 1 file+2 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+2 added−2 removed

  • other:+2 added−2 removed

1 file+2 added−2 removed

modified:src/builtin.jq+2 added-2 removed
46 unmodified lines
47 elif type == "string" and ($i|type) == "string" then _strindices($i)48 else .[$i] end;49def index($i): indices($i) | .[0]; # TODO: optimize50def rindex($i): indices($i) | .[-1:][0]; # TODO: optimize51def paths: path(recurse(if (type|. == "array" or . == "object") then .[] else empty end))|select(length > 0);52def paths(node_filter): . as $dot|paths|select(. as $p|$dot|getpath($p)|node_filter);51def paths: path(recurse)|select(length > 0);52def paths(node_filter): path(recurse|select(node_filter))|select(length > 0);53def isfinite: type == "number" and (isinfinite | not);54def arrays: select(type == "array");55def objects: select(type == "object");56def iterables: select(type|. == "array" or . == "object");
222 unmodified lines