summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNico Williams <nico@cryptonector.com>2014-12-23 23:37:25 -0600
committerNico Williams <nico@cryptonector.com>2014-12-23 23:37:25 -0600
commit2775b90b20d25fbc3f085e098da378afe0a201af (patch)
treec529381dc86c71e56a824064d911e3e23d21177e
parentae312bd7feeb33e81d8a5f9784d5e0e392655f8c (diff)
parentdc5e77ef8e41ba9d71424a0a5e97a7c929bffd0d (diff)
Merge pull request #601 from slapresta/redefine-any-all
Define {any,all}/0,1 in terms of {any,all}/2
-rw-r--r--builtin.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/builtin.c b/builtin.c
index c10dbe30..2d345fc7 100644
--- a/builtin.c
+++ b/builtin.c
@@ -978,22 +978,20 @@ 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"
+ " [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));",
+ " if . then . else empty end)] | length == 1;",
+ "def any(condition): any(.[]; condition);",
+ "def any: any(.);",
"def all(generator; condition): "
- " [true,"
- " foreach generator as $i"
+ " [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)] | length == 0;",
+ "def all(condition): all(.[]; condition);",
+ "def all: all(.);",
"def arrays: select(type == \"array\");",
"def objects: select(type == \"object\");",
"def iterables: arrays, objects;",