aboutsummaryrefslogtreecommitdiff
path: root/lib/types.nix
diff options
context:
space:
mode:
authorSilvan Mosberger <infinisil@icloud.com>2019-08-01 15:55:33 +0200
committerSilvan Mosberger <infinisil@icloud.com>2019-08-06 14:08:42 +0200
commit9a44f44d4c0d33775b63ad9dd387fd77f810074e (patch)
tree36292691567b9951c21260b1714654565898a49d /lib/types.nix
parentc6e7bc2977f728efcecfb954bbb38d436e98b798 (diff)
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 b225119299d..5612e999177 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: