Merge pull request #104744 from adisbladis/unique-foldl
lib.lists.unique: Switch from recursive function to using a fold
This commit is contained in:
commit
04150a003e
|
@ -640,13 +640,7 @@ rec {
|
|||
unique [ 3 2 3 4 ]
|
||||
=> [ 3 2 4 ]
|
||||
*/
|
||||
unique = list:
|
||||
if list == [] then
|
||||
[]
|
||||
else
|
||||
let
|
||||
x = head list;
|
||||
in [x] ++ unique (remove x list);
|
||||
unique = foldl' (acc: e: if elem e acc then acc else acc ++ [ e ]) [];
|
||||
|
||||
/* Intersects list 'e' and another list. O(nm) complexity.
|
||||
|
||||
|
|
Loading…
Reference in New Issue