maybeAsValue
maybeAsValue<
T>(x): [Nothing] extends [T] ?IsEqual<T,Nothing> extendstrue?undefined:Just<T> |undefined:Just<T>
This function checks if the provided Maybe value is a Just and returns the contained value. If the value is Nothing, it returns undefined, effectively handling optional values in your code.
Example
maybeAsValue("foobar")// => "foobar"
maybeAsValue(Nothing)// => undefinedType Parameters
• T extends unknown
The type of the value encapsulated by Just.
Parameters
x
T
The Maybe value to extract the value from.
Returns
[Nothing] extends [T] ? IsEqual<T, Nothing> extends true ? undefined : Just<T> | undefined : Just<T>
The value contained within Just, or undefined if the input is Nothing.