CombinatorswhenNothingwhenNothing CallablewhenNothing<T, M>(x: T, f: () => M): [Nothing] extends [T] ? IsEqual<T, Nothing> extends true ? M : M | Just<T> : TIf the given Maybe is a Nothing, then return the result of the given function, otherwise return the given Maybe. ExamplewhenNothing(Nothing, () => `foobar`)// => "foobar"whenNothing(0, () => `foobar`)// => 0Type parametersT: unknownThe maybe type.M: unknown = TThe mapped type.Parametersx: TThe Maybe value to map.f: () => MThe map function.Returns [Nothing] extends [T] ? IsEqual<T, Nothing> extends true ? M : M | Just<T> : TThe mapped value if Nothing.
If the given Maybe is a Nothing, then return the result of the given function, otherwise return the given Maybe.
Example