asMaybe
asMaybe<
T,N>(x,nothingValue?): [N] extends [T] ?IsEqual<T,N> extendstrue?Nothing:Maybe<Exclude<T,N>> :Exclude<T,N>
Creates a Maybe from the given value.
Example
asMaybe("foobar")// => "foobar"
asMaybe("foobar", "foobar")// => Nothing
asMaybe("foobar", "barfoo")// => "foobar"Type Parameters
• T
The Maybe type.
• N = undefined
Parameters
x
T
The value to unpack.
nothingValue?
N
The value to use as Nothing.
Returns
[N] extends [T] ? IsEqual<T, N> extends true ? Nothing : Maybe<Exclude<T, N>> : Exclude<T, N>
The maybe value.