summaryrefslogtreecommitdiffstats
path: root/lib/default.nix
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2022-12-20 19:08:42 +0100
committertv <tv@krebsco.de>2022-12-20 19:59:07 +0100
commitefbcfce7a78d12a5a6adebba5f1ec3bb9f602286 (patch)
treee536de600befe067a405cbd42b2dc75d80838cfa /lib/default.nix
parent212da586160c25fd919a308e5fbe30c9b5e565ca (diff)
lib: add uniq and uniqBy
Diffstat (limited to 'lib/default.nix')
-rw-r--r--lib/default.nix24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/default.nix b/lib/default.nix
index 1a57df266..280f04299 100644
--- a/lib/default.nix
+++ b/lib/default.nix
@@ -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