Skip to content

Commit

Permalink
add 01mf02's delpaths
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed Nov 15, 2024
1 parent 7a9dc45 commit 87ac98d
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions jqjq.jq
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,19 @@ def eval_ast($query; $path; $env; undefined_func):
end
);

def _delpaths($paths):
def _delpath($p):
( ($p | length) as $len
| if $len == 0 then error
elif $len == 1 then .[$p[0]] |= empty
else .[$p[0]] |= _delpath($p[1:])
end
);
reduce ($paths | sort | unique | reverse)[] as $p (
.;
_delpath($p)
);

def _e($query; $path; $env):
( . # debug({c: ., $query, $path, $env})
| ( $query
Expand Down Expand Up @@ -1583,10 +1596,10 @@ def eval_ast($query; $path; $env; undefined_func):
( a0 as $a0
| [[null], has($a0)]
)
# elif $name == "delpaths/1" then
# ( a0 as $a0
# | [[null], delpaths($a0)]
# )
elif $name == "delpaths/1" then
( a0 as $a0
| [[null], _delpaths($a0)]
)
elif $name == "explode/0" then [[null], explode]
elif $name == "implode/0" then [[null], implode]
elif $name == "tonumber/0" then [[null], tonumber]
Expand Down

0 comments on commit 87ac98d

Please sign in to comment.