Merge pull request #239722 from Stunkymonkey/lib-allUnique

lib.lists.allUnique: init

authored by Silvan Mosberger and committed by GitHub b04b7d64 486911d0

+23 -1
+1 -1
lib/default.nix
··· 92 concatMap flatten remove findSingle findFirst any all count 93 optional optionals toList range replicate partition zipListsWith zipLists 94 reverseList listDfs toposort sort naturalSort compareLists take 95 - drop sublist last init crossLists unique intersectLists 96 subtractLists mutuallyExclusive groupBy groupBy'; 97 inherit (self.strings) concatStrings concatMapStrings concatImapStrings 98 intersperse concatStringsSep concatMapStringsSep
··· 92 concatMap flatten remove findSingle findFirst any all count 93 optional optionals toList range replicate partition zipListsWith zipLists 94 reverseList listDfs toposort sort naturalSort compareLists take 95 + drop sublist last init crossLists unique allUnique intersectLists 96 subtractLists mutuallyExclusive groupBy groupBy'; 97 inherit (self.strings) concatStrings concatMapStrings concatImapStrings 98 intersperse concatStringsSep concatMapStringsSep
+13
lib/lists.nix
··· 821 */ 822 unique = foldl' (acc: e: if elem e acc then acc else acc ++ [ e ]) []; 823 824 /* Intersects list 'e' and another list. O(nm) complexity. 825 826 Example:
··· 821 */ 822 unique = foldl' (acc: e: if elem e acc then acc else acc ++ [ e ]) []; 823 824 + /* Check if list contains only unique elements. O(n^2) complexity. 825 + 826 + Type: allUnique :: [a] -> bool 827 + 828 + Example: 829 + allUnique [ 3 2 3 4 ] 830 + => false 831 + allUnique [ 3 2 4 1 ] 832 + => true 833 + */ 834 + allUnique = list: (length (unique list) == length list); 835 + 836 + 837 /* Intersects list 'e' and another list. O(nm) complexity. 838 839 Example:
+9
lib/tests/misc.nix
··· 726 expected = 7; 727 }; 728 729 # ATTRSETS 730 731 testConcatMapAttrs = {
··· 726 expected = 7; 727 }; 728 729 + testAllUnique_true = { 730 + expr = allUnique [ 3 2 4 1 ]; 731 + expected = true; 732 + }; 733 + testAllUnique_false = { 734 + expr = allUnique [ 3 2 3 4 ]; 735 + expected = false; 736 + }; 737 + 738 # ATTRSETS 739 740 testConcatMapAttrs = {