summaryrefslogtreecommitdiffstats
path: root/lib/types.nix
diff options
context:
space:
mode:
authorAaron Andersen <aaron@fosslib.net>2019-08-13 11:48:42 -0400
committerGitHub <noreply@github.com>2019-08-13 11:48:42 -0400
commit6f6468bef34394b5c63aaa46fe20965993420600 (patch)
tree894c55c5e6140c956eb7e63b75e0a1b3b99ddd1c /lib/types.nix
parent8a95dfd829cdcd83c4fbd5046e354d84db3f6738 (diff)
parent88bb9fa4037c7cda4cb2fb94792d17e44fd55a18 (diff)
Merge pull request #65728 from Infinisil/types-eithers
lib/types: Add oneOf, extension of either to a list of types
Diffstat (limited to 'lib/types.nix')
-rw-r--r--lib/types.nix7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/types.nix b/lib/types.nix
index e22bcd326c86..9c00656ab918 100644
--- a/lib/types.nix
+++ b/lib/types.nix
@@ -443,6 +443,13 @@ rec {
functor = (defaultFunctor name) // { wrapped = [ t1 t2 ]; };
};
+ # Any of the types in the given list
+ oneOf = ts:
+ let
+ head' = if ts == [] then throw "types.oneOf needs to get at least one type in its argument" else head ts;
+ tail' = tail ts;
+ in foldl' either head' tail';
+
# Either value of type `finalType` or `coercedType`, the latter is
# converted to `finalType` using `coerceFunc`.
coercedTo = coercedType: coerceFunc: finalType: