mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-22 06:53:01 +00:00
lib.lists.allUnique: init
This commit is contained in:
parent
b5bd1053d2
commit
66261e9961
@ -92,7 +92,7 @@ let
|
||||
concatMap flatten remove findSingle findFirst any all count
|
||||
optional optionals toList range replicate partition zipListsWith zipLists
|
||||
reverseList listDfs toposort sort naturalSort compareLists take
|
||||
drop sublist last init crossLists unique intersectLists
|
||||
drop sublist last init crossLists unique allUnique intersectLists
|
||||
subtractLists mutuallyExclusive groupBy groupBy';
|
||||
inherit (self.strings) concatStrings concatMapStrings concatImapStrings
|
||||
intersperse concatStringsSep concatMapStringsSep
|
||||
|
@ -821,6 +821,19 @@ rec {
|
||||
*/
|
||||
unique = foldl' (acc: e: if elem e acc then acc else acc ++ [ e ]) [];
|
||||
|
||||
/* Check if list contains only unique elements. O(n^2) complexity.
|
||||
|
||||
Type: allUnique :: [a] -> bool
|
||||
|
||||
Example:
|
||||
allUnique [ 3 2 3 4 ]
|
||||
=> false
|
||||
allUnique [ 3 2 4 1 ]
|
||||
=> true
|
||||
*/
|
||||
allUnique = list: (length (unique list) == length list);
|
||||
|
||||
|
||||
/* Intersects list 'e' and another list. O(nm) complexity.
|
||||
|
||||
Example:
|
||||
|
@ -726,6 +726,15 @@ runTests {
|
||||
expected = 7;
|
||||
};
|
||||
|
||||
testAllUnique_true = {
|
||||
expr = allUnique [ 3 2 4 1 ];
|
||||
expected = true;
|
||||
};
|
||||
testAllUnique_false = {
|
||||
expr = allUnique [ 3 2 3 4 ];
|
||||
expected = false;
|
||||
};
|
||||
|
||||
# ATTRSETS
|
||||
|
||||
testConcatMapAttrs = {
|
||||
|
Loading…
Reference in New Issue
Block a user