diff options
author | Aaron Andersen <aaron@fosslib.net> | 2019-08-13 11:48:42 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-13 11:48:42 -0400 |
commit | 6f6468bef34394b5c63aaa46fe20965993420600 (patch) | |
tree | 894c55c5e6140c956eb7e63b75e0a1b3b99ddd1c /lib/types.nix | |
parent | 8a95dfd829cdcd83c4fbd5046e354d84db3f6738 (diff) | |
parent | 88bb9fa4037c7cda4cb2fb94792d17e44fd55a18 (diff) | |
download | nixpkgs-6f6468bef34394b5c63aaa46fe20965993420600.tar nixpkgs-6f6468bef34394b5c63aaa46fe20965993420600.tar.gz nixpkgs-6f6468bef34394b5c63aaa46fe20965993420600.tar.bz2 nixpkgs-6f6468bef34394b5c63aaa46fe20965993420600.tar.lz nixpkgs-6f6468bef34394b5c63aaa46fe20965993420600.tar.xz nixpkgs-6f6468bef34394b5c63aaa46fe20965993420600.tar.zst nixpkgs-6f6468bef34394b5c63aaa46fe20965993420600.zip |
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.nix | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/types.nix b/lib/types.nix index e22bcd326c8..9c00656ab91 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: |