git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #144072 from polykernel/lib-lists-mutuallyexclusive-optimization
commit481afad2658993463d390b184e259d73fcd374ea authorBen Siraphob <bensiraphob@gmail.com> dateTue 2 Nov 2021, 02:46 (5 years ago) parent94d91a4cd63975
1 file changed+2−5
lib/lists.nix+2−5
lib/lists.nix+2−5
@@ -642,7 +642,7 @@ rec {
642642 unique [ 3 2 3 4 ]
643643 => [ 3 2 4 ]
644644 */
645− unique = foldl' (acc: e: if elem e acc then acc else acc ++ [ e ]) [];
645+ unique = foldl' (acc: e: if elem e acc then acc else acc ++ [ e ]) [];
646646
647647 /* Intersects list 'e' and another list. O(nm) complexity.
648648
@@ -663,9 +663,6 @@ rec {
663663 /* Test if two lists have no common element.
664664 It should be slightly more efficient than (intersectLists a b == [])
665665 */
666− mutuallyExclusive = a: b:
667− (builtins.length a) == 0 ||
668− (!(builtins.elem (builtins.head a) b) &&
669− mutuallyExclusive (builtins.tail a) b);
666+ mutuallyExclusive = a: b: length a == 0 || !(any (x: elem x a) b);
670667
671668}