builtin: add pick(stream)

pick(stream) works on both arrays and objects

Restrictions on the dot-paths are specified in manual.yml

See #2578
This commit is contained in:
pkoppstein authored and Nico Williams committed 2023-07-05 23:48:31 -05:00
1 parent a881532b29
commit 416e8ada7d
3 files changed
+32

No files matched your search

+6
View File
@@ -260,6 +260,12 @@ def walk(f):
else f
end;
# stream should be a stream of dot-paths
def pick(stream):
. as $in
| reduce path(stream) as $a (null;
setpath($a; $in|getpath($a)) );
# SQL-ish operators here:
def INDEX(stream; idx_expr):
reduce stream as $row ({}; .[$row|idx_expr|tostring] = $row);