git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #104744 from adisbladis/unique-foldl

lib.lists.unique: Switch from recursive function to using a fold

commit04150a003ea363f8e365bab1d1b3cae721e3fe2f authoradisbladis <adisbladis@gmail.com> dateTue 24 Nov 2020, 14:55 (6 years ago) parent91f1d7e85605c8
1 file changed+1−7
lib/lists.nix+1−7
lib/lists.nix+1−7
@@ -640,13 +640,7 @@ rec {
640640 unique [ 3 2 3 4 ]
641641 => [ 3 2 4 ]
642642 */
643− unique = list:
644− if list == [] then
645− []
646− else
647− let
648− x = head list;
649− in [x] ++ unique (remove x list);
643+ unique = foldl' (acc: e: if elem e acc then acc else acc ++ [ e ]) [];
650644
651645 /* Intersects list 'e' and another list. O(nm) complexity.
652646