coercedTo
lib.types.coercedTo
Docs pulled from | This Revision | 10 minutes ago
converted to finalType
using coerceFunc
.
Noogle detected
Implementation
The following is the current implementation of this function.
coercedTo =
coercedType: coerceFunc: finalType:
assert lib.assertMsg (
coercedType.getSubModules == null
) "coercedTo: coercedType must not have submodules (it’s a ${coercedType.description})";
mkOptionType rec {
name = "coercedTo";
description = "${optionDescriptionPhrase (class: class == "noun") finalType} or ${
optionDescriptionPhrase (class: class == "noun") coercedType
} convertible to it";
check = x: (coercedType.check x && finalType.check (coerceFunc x)) || finalType.check x;
merge =
loc: defs:
let
coerceVal = val: if coercedType.check val then coerceFunc val else val;
in
finalType.merge loc (map (def: def // { value = coerceVal def.value; }) defs);
emptyValue = finalType.emptyValue;
getSubOptions = finalType.getSubOptions;
getSubModules = finalType.getSubModules;
substSubModules = m: coercedTo coercedType coerceFunc (finalType.substSubModules m);
typeMerge = t: null;
functor = (defaultFunctor name) // {
wrappedDeprecationMessage = makeWrappedDeprecationMessage { elemType = finalType; };
};
nestedTypes.coercedType = coercedType;
nestedTypes.finalType = finalType;
};