Skip to content

Commit

Permalink
funcs: Add delta/0 delta_by/0
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed Sep 12, 2021
1 parent 96f7a75 commit 01d8a90
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/interp/funcs.jq
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 01d8a90

Please sign in to comment.