diff --git a/lib/lists.nix b/lib/lists.nix index 927358af7c1..ed1b7e74399 100644 --- a/lib/lists.nix +++ b/lib/lists.nix @@ -625,13 +625,15 @@ rec { => [ 3 2 4 ] */ unique = list: - if list == [] then - [] - else - let - x = head list; - xs = unique (drop 1 list); - in [x] ++ remove x xs; + let isFirst = value: end: + if end == 0 then true else + if elemAt list (end - 1) == value then false + else isFirst value (end - 1); + in concatMap (index: + let value = elemAt list index; + shouldInclude = isFirst value index; + in optional shouldInclude value + ) (range 0 (length list - 1)); /* Intersects list 'e' and another list. O(nm) complexity.