mirror of
https://github.com/wader/fq.git
synced 2024-11-27 14:14:58 +03:00
funcs: Add delta/0 delta_by/0
This commit is contained in:
parent
96f7a750b9
commit
01d8a902eb
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user