lib: add uniq and uniqBy

This commit is contained in:
tv 2022-12-20 19:08:42 +01:00
parent 212da58616
commit efbcfce7a7
1 changed files with 24 additions and 0 deletions

View File

@ -187,6 +187,30 @@ let
in
filter (x: x != []) ([acc.chunk] ++ acc.chunks);
# Filter adjacent duplicate elements.
uniq = uniqBy eq;
# Filter adjacent duplicate elements determined via the given function.
uniqBy = cmp: let
f = a: s:
if length s == 0 then
[]
else let
b = head s;
in
if cmp a b then
f b (tail s)
else
[b] ++ f b (tail s);
in
s:
if length s == 0 then
[]
else let
b = head s;
in
[b] ++ f b (tail s);
warnOldVersion = oldName: newName:
if compareVersions oldName newName != -1 then
trace "Upstream `${oldName}' gets overridden by `${newName}'." newName