summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSantiago Lapresta <santiago.lapresta@gmail.com>2014-02-17 04:01:32 +0100
committerSantiago Lapresta <santiago.lapresta@gmail.com>2014-02-17 04:01:32 +0100
commit8b41415b071225c8ff25cb7938ed19e258cc8827 (patch)
treef9720a6e74bc5e28db0aa8acce8a019c1e8484ab
parent1fa55a3fae3dc6b8a2018ce64786b5b5570fde70 (diff)
Added `all` and `any` builtins
-rw-r--r--builtin.c2
-rw-r--r--docs/content/3.manual/manual.yml40
2 files changed, 42 insertions, 0 deletions
diff --git a/builtin.c b/builtin.c
index aac993db..ddf66d00 100644
--- a/builtin.c
+++ b/builtin.c
@@ -680,6 +680,8 @@ static const char* const jq_builtins[] = {
"def rindex(i): .[i][-1:][0];",
"def paths: path(recurse(if (type|. == \"array\" or . == \"object\") then .[] else empty end))|select(length > 0);",
"def leaf_paths: . as $dot|paths|select(. as $p|$dot|getpath($p)|type|. != \"array\" and . != \"object\");",
+ "def any: reduce .[] as $i (false; . or $i);",
+ "def all: reduce .[] as $i (true; . and $i);",
};
diff --git a/docs/content/3.manual/manual.yml b/docs/content/3.manual/manual.yml
index ff9d429a..fec50d0d 100644
--- a/docs/content/3.manual/manual.yml
+++ b/docs/content/3.manual/manual.yml
@@ -690,6 +690,46 @@ sections:
input: '[]'
output: ["null"]
+ - title: `any`
+ body: |
+
+ The filter `any` takes as input an array of boolean values,
+ and produces `true` as output if any of the the elements of
+ the array is `true`.
+
+ If the input is an empty array, `any` returns `false`.
+
+ examples:
+ - program: any
+ input: '[true, false]'
+ output: ["true"]
+ - program: any
+ input: '[false, false]'
+ output: ["false"]
+ - program: any
+ input: '[]'
+ output: ["false"]
+
+ - title: `all`
+ 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`.
+
+ If the input is an empty array, `all` returns `true`.
+
+ examples:
+ - program: all
+ input: '[true, false]'
+ output: ["false"]
+ - program: all
+ input: '[true, true]'
+ output: ["true"]
+ - program: all
+ input: '[]'
+ output: ["true"]
+
- title: `range`
body: |