whenNothing
whenNothing<
T,M>(x,f): [Nothing] extends [T] ?IsEqual<T,Nothing> extendstrue?M:M|Just<T> :T
If the given Maybe is a Nothing, then return the result of the given function, otherwise return the given Maybe.
Example
whenNothing(Nothing, () => `foobar`)// => "foobar"
whenNothing(0, () => `foobar`)// => 0Type Parameters
• T extends unknown
The maybe type.
• M extends unknown = T
The mapped type.
Parameters
x
T
The Maybe value to map.
f
() => M
The map function.
Returns
[Nothing] extends [T] ? IsEqual<T, Nothing> extends true ? M : M | Just<T> : T
The mapped value if Nothing.