diff options
author | Santiago Lapresta <santiago.lapresta@gmail.com> | 2014-05-12 01:37:27 +0200 |
---|---|---|
committer | Santiago Lapresta <santiago.lapresta@gmail.com> | 2014-05-12 01:37:27 +0200 |
commit | 41a093c1f221fe36025580ed6616b30563516cc0 (patch) | |
tree | 6746a7d91e970ef769b1d94abb9510c7e66d0d2f | |
parent | 022a4188944bfd12cfd0dedef61644ac49e3fa13 (diff) |
Added unique_by function
-rw-r--r-- | builtin.c | 1 | ||||
-rw-r--r-- | docs/content/3.manual/manual.yml | 15 |
2 files changed, 16 insertions, 0 deletions
@@ -664,6 +664,7 @@ static const char* const jq_builtins[] = { "def sort_by(f): _sort_by_impl(map([f]));", "def group_by(f): _group_by_impl(map([f]));", "def unique: group_by(.) | map(.[0]);", + "def unique_by(f): group_by(f) | map(.[0]);", "def max_by(f): _max_by_impl(map([f]));", "def min_by(f): _min_by_impl(map([f]));", #include "libm.h" diff --git a/docs/content/3.manual/manual.yml b/docs/content/3.manual/manual.yml index c8fcb5fa..2e2fb366 100644 --- a/docs/content/3.manual/manual.yml +++ b/docs/content/3.manual/manual.yml @@ -931,6 +931,21 @@ sections: input: '[1,2,5,3,5,3,1,3]' output: ['[1,2,3,5]'] + - title: `unique_by` + body: | + + The `unique_by(.foo)` function takes as input an array and produces + an array of the same elements, in sorted order, with + elqements with a duplicate `.foo` field removed. Think of it as making + an array by taking one element out of every group produced by + `group_by`. + + examples: + - program: 'unique' + input: '[1,2,5,3,5,3,1,3]' + output: ['[1,2,3,5]'] + + - title: `reverse` body: | |