git.iko.soy/typeable/nixpkgs
on master help sign in
lib.lists.unique: Switch from recursive function to using a fold
85605c8adisbladis
lib/lists.nix+1−7
@@ -640,13 +640,7 @@ rec {
640 unique [ 3 2 3 4 ]
640 unique [ 3 2 3 4 ]
641 => [ 3 2 4 ]
641 => [ 3 2 4 ]
642 */
642 */
643− unique = list:
643+ unique = foldl' (acc: e: if elem e acc then acc else acc ++ [ e ]) [];
644− if list == [] then
645− []
646− else
647− let
648− x = head list;
649− in [x] ++ unique (remove x list);
650
644
651 /* Intersects list 'e' and another list. O(nm) complexity.
645 /* Intersects list 'e' and another list. O(nm) complexity.
652
646