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?
Unwraps one level of nested Opts. Similar to flatten in other libraries or languages.
flatten
joinOpt(some(none)) // None joinOpt(some(some(1))) // Some(1)
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 numbers lesser than 0 returns None, otherwise acts same as opt. Useful for strange functions which return -1 or other negative numbers on failure.
0
-1
optNegative(undefined) // None optNegative(1) // Some(1) optNegative(0) // Some(0) optNegative(-1) // None
For a number 0 returns None, otherwise acts same as opt.
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.