Readonly
variantNothing
is always Variant.Nothing
.
Method variant for equals
Method variant for get
If you have a Maybe
of an object type, you can do thatMaybe.get('a key')
to look up the next layer down in the object.
type DeepOptionalType = {
something?: {
with?: {
deeperKeys?: string;
}
}
};
const fullySet: DeepType = {
something: {
with: {
deeperKeys: 'like this'
}
}
};
const deepJust = Maybe.of(fullySet)
.get('something')
.get('with')
.get('deeperKeys');
console.log(deepJust); // Just('like this');
const partiallyUnset: DeepType = { something: { } };
const deepEmpty = Maybe.of(partiallyUnset)
.get('something')
.get('with')
.get('deeperKeys');
console.log(deepEmpty); // Nothing
Method variant for toString
A
Nothing
instance is the absent variant instance of theMaybe
type, representing the presence of a value which may be absent. For a full discussion, see the module docs.