Merge pull request #296 from slapresta/all-any
Added `all` and `any` builtins
This commit is contained in:
commit
b23fae9ee3
2 files changed
+42
No files matched your search
@@ -680,6 +680,8 @@ static const char* const jq_builtins[] = {
|
|||||||
"def rindex(i): .[i][-1:][0];",
|
"def rindex(i): .[i][-1:][0];",
|
||||||
"def paths: path(recurse(if (type|. == \"array\" or . == \"object\") then .[] else empty end))|select(length > 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 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);",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -690,6 +690,46 @@ sections:
|
|||||||
input: '[]'
|
input: '[]'
|
||||||
output: ["null"]
|
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`
|
- title: `range`
|
||||||
body: |
|
body: |
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user