]> granicus.if.org Git - jq/commitdiff
Define {any,all}/{0,1} in terms of {any,all}/2
authorSantiago Lapresta <santiago.lapresta@gmail.com>
Mon, 20 Oct 2014 16:16:03 +0000 (18:16 +0200)
committerSantiago Lapresta <santiago.lapresta@gmail.com>
Mon, 20 Oct 2014 20:01:25 +0000 (22:01 +0200)
builtin.c

index ddd207b350453b882fffb92573fb8b652ec09c9f..7099ab260682c924b92933a278568390eeb99137 100644 (file)
--- a/builtin.c
+++ b/builtin.c
@@ -978,22 +978,22 @@ static const char* const jq_builtins[] = {
   "def rindex($i):  if type == \"array\" and ($i|type) == \"array\" then .[$i] elif type == \"array\" then .[[$i]] else .[$i] end | .[-1:][0];",
   "def paths: path(recurse(if (type|. == \"array\" or . == \"object\") then .[] else empty end))|select(length > 0);",
   "def paths(node_filter): . as $dot|paths|select(. as $p|$dot|getpath($p)|node_filter);",
-  "def any: reduce .[] as $i (false; . or $i);",
-  "def all: reduce .[] as $i (true; . and $i);",
-  "def any(condition): reduce .[] as $i (false; . or ($i|condition));",
   "def any(generator; condition):"
   "         [false,"
   "         foreach generator as $i"
   "                 (false;"
   "                  if . then break elif $i | condition then true else . end;"
   "                  if . then . else empty end)] | any;",
-  "def all(condition): reduce .[] as $i (true; . and ($i|condition));",
+  "def any(condition): any(.[]; condition);",
+  "def any: any(.);",
   "def all(generator; condition): "
   "         [true,"
   "         foreach generator as $i"
   "                 (true;"
   "                  if .|not then break elif $i | condition then . else false end;"
-  "                  if .|not then . else empty end)]|all;",
+  "                  if .|not then . else empty end)] | all;",
+  "def all(condition): all(.[]; condition);",
+  "def all: all(.);",
   "def arrays: select(type == \"array\");",
   "def objects: select(type == \"object\");",
   "def iterables: arrays, objects;",