From 01d8a902eba2e987176b9b7851335e88c752266b Mon Sep 17 00:00:00 2001 From: Mattias Wadman Date: Fri, 27 Aug 2021 15:04:07 +0200 Subject: [PATCH] funcs: Add delta/0 delta_by/0 --- pkg/interp/funcs.jq | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/interp/funcs.jq b/pkg/interp/funcs.jq index 2a4b7364..7e3ff7a0 100644 --- a/pkg/interp/funcs.jq +++ b/pkg/interp/funcs.jq @@ -89,6 +89,20 @@ def count_by(exp): group_by(exp) | map([(.[0] | exp), length]); def count: count_by(.); +# array of result of applying f on all consecutive pairs +def delta_by(f): + ( . as $a + | if length < 1 then [] + else + [ range(length-1) as $i + | {a: $a[$i], b: $a[$i+1]} + | f + ] + end + ); +# array of minus between all consecutive pairs +def delta: delta_by(.b - .a); + # helper to build path query/generate functions for tree structures with # non-unique children, ex: mp4_path def tree_path(children; name; $v):