Single global instance of None.
<A, B>(of: Opt<(_: A) => B>) => (oa: Opt<A>): Opt<B>
Apply oa to function of. If any argument is None then result is None.
oa
of
ap(opt(x => x > 0))(opt(1)) // Opt(true) ap(opt(x => x > 0))(none) // None ap(none)(opt(1)) // None ap(none)(none) // None
input of function inside of
output of function inside of
<A, B>(f: (_: A) => B) => (oa: Opt<A>): Opt<B>
Apply oa to function f. If argument is None then result is None.
f
apFn(x => x > 0)(opt(1)) // Opt(true) apFn(x => x > 0)(none) // None
input of function f
output of function f
Transforms array of opts into an array where Nones are omitted and Somes are unwrapped.
catOpts([opt(1), opt(null)]) // [1]
Is given value an instance of Opt?
Similar to Array.map, but also allows omitting elements.
Array.map
mapOpt((x: number) => x > 0 ? opt(x) : none)([-1, 0, 1]) // [1]
Main constructor function - for undefined, null and NaN returns None. Anything else is wrapped into Some.
undefined
null
NaN
For empty array ([]) returns None, otherwise acts same as opt.
[]
For empty object ({}) returns None, otherwise acts same as opt.
{}
For empty string ('') returns None, otherwise acts same as opt.
''
For falsy values returns None, otherwise acts same as opt.
optFalsy(''); // None optFalsy(0); // None optFalsy(false); // None optFalsy(NaN); // None
For a number 0 returns None, otherwise acts same as opt.
0
Constructs Some. Usually it is opt you are looking for (only in rare cases you want to have for example Some(undefined)).
Some(undefined)
Generated using TypeDoc
Single global instance of None.