static const char* const jq_builtins[] = {
"def error: error(.);",
"def map(f): [.[] | f];",
- "def map_values(f): .[] |= f;",
"def select(f): if f then . else empty end;",
"def sort_by(f): _sort_by_impl(map([f]));",
"def group_by(f): _group_by_impl(map([f]));",
"def del(f): delpaths([path(f)]);",
"def _assign(paths; value): value as $v | reduce path(paths) as $p (.; setpath($p; $v));",
"def _modify(paths; update): reduce path(paths) as $p (.; setpath($p; getpath($p) | update));",
+ "def map_values(f): .[] |= f;",
// recurse
"def recurse(f): def r: ., (f | select(. != null) | r); r;",
[[], [1,2,3], ["a","b","c"], [[3],[4,5],[6]], [{"a":1}, {"b":2}, {"a":3}]]
[null, 6, "abc", [3,4,5,6], {"a":3, "b": 2}]
+map_values(.+1)
+[0,1,2]
+[1,2,3]
+
#
# User-defined functions
# Oh god.