Add any/N and all/N x N in (1, 2) (fix #455)

Contributed by @pkoppstein.
This commit is contained in:
Nicolas Williams committed 2014-07-06 20:08:06 -05:00
1 parent 5a863bf010
commit 821cd31e67
2 files changed
+18 -2

No files matched your search

+4
View File
@@ -934,6 +934,10 @@ static const char* const jq_builtins[] = {
"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 all(condition): reduce .[] as $i (true; . and ($i|condition));",
"def any(generator; condition): reduce generator as $i (false; . or ($i|condition));",
"def all(generator; condition): reduce generator as $i (true; . and ($i|condition));",
"def arrays: select(type == \"array\");",
"def objects: select(type == \"object\");",
"def iterables: arrays, objects;",
+14 -2
View File
@@ -766,7 +766,7 @@ sections:
input: '[]'
output: ["null"]
- title: "`any`"
- title: "`any`, `any(condition), `any(generator; condition)`"
body: |
The filter `any` takes as input an array of boolean values,
@@ -775,6 +775,12 @@ sections:
If the input is an empty array, `any` returns `false`.
The `any(condition)` form applies the given condition to the
elements of the input array.
The `any(generator; condition)` form applies the given
condition to all the outputs of the given generator.
examples:
- program: any
input: '[true, false]'
@@ -786,13 +792,19 @@ sections:
input: '[]'
output: ["false"]
- title: "`all`"
- title: "`all`, `all(condition), `all(generator; condition)`"
body: |
The filter `all` takes as input an array of boolean values,
and produces `true` as output if all of the the elements of
the array are `true`.
The `all(condition)` form applies the given condition to the
elements of the input array.
The `all(generator; condition)` form applies the given
condition to all the outputs of the given generator.
If the input is an empty array, `all` returns `true`.
examples: