Simple and efficient implementation of walk/1 (#2795)
This commit is contained in:
1 parent
0f80921268
commit
4d4c17ca6a
2 files changed
+27
-7
No files matched your search
+8
-7
@@ -246,13 +246,14 @@ def bsearch($target):
|
||||
|
||||
# Apply f to composite entities recursively, and to atoms
|
||||
def walk(f):
|
||||
. as $in
|
||||
| if type == "object" then
|
||||
reduce keys_unsorted[] as $key
|
||||
( {}; . + { ($key): ($in[$key] | walk(f)) } ) | f
|
||||
elif type == "array" then map( walk(f) ) | f
|
||||
else f
|
||||
end;
|
||||
def w:
|
||||
if type == "object"
|
||||
then map_values(w)
|
||||
elif type == "array" then map(w)
|
||||
else .
|
||||
end
|
||||
| f;
|
||||
w;
|
||||
|
||||
# pathexps could be a stream of dot-paths
|
||||
def pick(pathexps):
|
||||
|
||||
Reference in new issue
Block a user