From 72735167f9cdcd10b5e411df4acb05174218f890 Mon Sep 17 00:00:00 2001 From: Santiago Lapresta Date: Mon, 20 Oct 2014 18:16:03 +0200 Subject: [PATCH 1/2] Define {any,all}/{0,1} in terms of {any,all}/2 --- builtin.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/builtin.c b/builtin.c index ddd207b3..7099ab26 100644 --- 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;", From dc5e77ef8e41ba9d71424a0a5e97a7c929bffd0d Mon Sep 17 00:00:00 2001 From: Santiago Lapresta Date: Tue, 21 Oct 2014 13:00:38 +0200 Subject: [PATCH 2/2] Define {any,all}/2 independently from {any,all}/0 --- builtin.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/builtin.c b/builtin.c index 7099ab26..b43ad64b 100644 --- a/builtin.c +++ b/builtin.c @@ -979,19 +979,17 @@ static const char* const jq_builtins[] = { "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(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;", + " 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\");",