summaryrefslogtreecommitdiffstats
path: root/builtin.c
diff options
context:
space:
mode:
authorpkoppstein <pkoppstein@gmail.com>2014-08-03 19:49:02 -0400
committerNicolas Williams <nico@cryptonector.com>2014-08-04 21:11:01 -0500
commitf8fed0f0bc020d09fdbfed7cbd672ff1cfd5dfef (patch)
tree06946adde757d64289ce60705e80a188b19885fc /builtin.c
parenta2f99d43c35ea9eb563c7bb36e9d468bbe5382ef (diff)
Apply TCO to recurse/1, add recurse/2; tweak docs
Signed-off-by: Nicolas Williams <nico@cryptonector.com>
Diffstat (limited to 'builtin.c')
-rw-r--r--builtin.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/builtin.c b/builtin.c
index b6da4be8..4fb496cd 100644
--- a/builtin.c
+++ b/builtin.c
@@ -928,9 +928,13 @@ static const char* const jq_builtins[] = {
"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 recurse(f): ., (f | select(. != null) | recurse(f));",
+
+ // recurse
+ "def recurse(f): def r: ., (f | select(. != null) | r); r;",
+ "def recurse(f; cond): def r: ., (f | select(cond) | r); r;",
"def recurse: recurse(.[]?);",
"def recurse_down: recurse;",
+
"def to_entries: [keys[] as $k | {key: $k, value: .[$k]}];",
"def from_entries: map({(.key): .value}) | add | .//={};",
"def with_entries(f): to_entries | map(f) | from_entries;",