Merge pull request #65728 from Infinisil/types-eithers
lib/types: Add oneOf, extension of either to a list of types
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user