summaryrefslogtreecommitdiffstats
path: root/builtin.c
diff options
context:
space:
mode:
authorStephen Dolan <mu@netsoc.tcd.ie>2012-12-29 16:43:36 +0000
committerStephen Dolan <mu@netsoc.tcd.ie>2012-12-29 16:43:36 +0000
commitd5fdf70434a243e6f3bd6967dbc2d28c9144cb29 (patch)
tree17901a90c2a2ff0a2219fa9bab9a340af95e36c7 /builtin.c
parent465a4ec565a106e0e4cc1d64214fb2d6d791c8dc (diff)
Refactor assignment.
New version is much more elegant and probably slower. Uses library functions implemented in jq rather than dedicated opcodes.
Diffstat (limited to 'builtin.c')
-rw-r--r--builtin.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/builtin.c b/builtin.c
index dca3d6ff..f5917cbe 100644
--- a/builtin.c
+++ b/builtin.c
@@ -552,6 +552,9 @@ static const char* jq_builtins[] = {
"def max_by(f): _max_by_impl(map([f]));",
"def min_by(f): _min_by_impl(map([f]));",
"def del(f): delpaths([path(f)]);",
+ "def _assign(paths; value): value as $v | fold . as $obj (path(paths) as $p | $obj | setpath($p; $v));",
+ "def _modify(paths; update): fold . as $obj (path(paths) as $p | $obj | setpath($p; getpath($p) | update));",
+
};