unique
lib.lists.unique
Docs pulled from | This Revision | 1 day ago
Remove duplicate elements from the list
. O(n^2) complexity.
If the list only contains strings and order is not important, the complexity can be reduced to O(n log n) by using lib.lists.uniqueStrings
instead.
Inputs
list
-
Input list
Type
unique :: [a] -> [a]
Examples
lib.lists.unique
usage example
unique [ 3 2 3 4 ]
=> [ 3 2 4 ]
Noogle detected
Implementation
This function is implemented in c++ and is part of the native nix runtime.
Implementation
The following is the current implementation of this function.
unique = foldl' (acc: e: if elem e acc then acc else acc ++ [ e ]) [ ];