diff options
author | tv <tv@krebsco.de> | 2022-12-20 19:08:42 +0100 |
---|---|---|
committer | tv <tv@krebsco.de> | 2022-12-20 19:59:07 +0100 |
commit | 6c4e84fe87aace5daf6915f26ea930a99b149555 (patch) | |
tree | f9b6b88faaa6e7b3b847421fb1f20462d2edeaff /lib/default.nix | |
parent | 19701a1ed870ea1846fdb931b2a52f8b6f0ea24c (diff) |
lib: add uniq and uniqBy
Diffstat (limited to 'lib/default.nix')
-rw-r--r-- | lib/default.nix | 24 |
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 |