coercedTo
lib.types.coercedTo
Docs pulled from | This Revision | about 1 hour 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 = {
__functor =
self: loc: defs:
(self.v2 { inherit loc defs; }).value;
v2 =
{ loc, defs }:
let
finalDefs = (
map (
def:
def
// {
value =
let
merged = coercedType.merge.v2 {
inherit loc;
defs = [ def ];
};
in
if coercedType.merge ? v2 then
if merged.headError == null then coerceFunc def.value else def.value
else if coercedType.check def.value then
coerceFunc def.value
else
def.value;
}
) defs
);
in
if finalType.merge ? v2 then
finalType.merge.v2 {
inherit loc;
defs = finalDefs;
}
else
{
value = finalType.merge loc finalDefs;
valueMeta = { };
headError = checkDefsForError check loc 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;
};