summaryrefslogtreecommitdiffstats
path: root/lib
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
commit6c4e84fe87aace5daf6915f26ea930a99b149555 (patch)
treef9b6b88faaa6e7b3b847421fb1f20462d2edeaff /lib
parent19701a1ed870ea1846fdb931b2a52f8b6f0ea24c (diff)
lib: add uniq and uniqBy
Diffstat (limited to 'lib')
-rw-r--r--lib/default.nix24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/default.nix b/lib/default.nix
index 1a57df2..280f042 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