mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-01 15:11:25 +00:00
lib.lists.mutuallyExclusive: add function
This commit is contained in:
parent
5afcdc88fa
commit
dfc004e69c
@ -477,4 +477,12 @@ rec {
|
||||
*/
|
||||
subtractLists = e: filter (x: !(elem x e));
|
||||
|
||||
/* Test if two lists have no common element.
|
||||
It should be slightly more efficient than (intersectLists a b == [])
|
||||
*/
|
||||
mutuallyExclusive = a: b:
|
||||
(builtins.length a) == 0 ||
|
||||
(!(builtins.elem (builtins.head a) b) &&
|
||||
mutuallyExclusive (builtins.tail a) b);
|
||||
|
||||
}
|
||||
|
@ -45,13 +45,8 @@ let
|
||||
throw ''‘${showLicense license}’ is not an attribute of lib.licenses''
|
||||
) list;
|
||||
|
||||
mutuallyExclusive = a: b:
|
||||
(builtins.length a) == 0 ||
|
||||
(!(builtins.elem (builtins.head a) b) &&
|
||||
mutuallyExclusive (builtins.tail a) b);
|
||||
|
||||
areLicenseListsValid =
|
||||
if mutuallyExclusive whitelist blacklist then
|
||||
if lib.mutuallyExclusive whitelist blacklist then
|
||||
assert onlyLicenses whitelist; assert onlyLicenses blacklist; true
|
||||
else
|
||||
throw "whitelistedLicenses and blacklistedLicenses are not mutually exclusive.";
|
||||
|
Loading…
Reference in New Issue
Block a user