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
Opt.bimap
Opt.caseOf
Transforms array of opts into an array where Nones are omitted and Somes are unwrapped.
catOpts([opt(1), opt(null)]) // [1]
Opt.flatMap
Opt.chainToOpt
Opt.contains
Opt.equals
Opt.exists
Same as Opt.filter, but also supports arrays.
Opt.filter
Same as Opt.flatMap, but also supports arrays.
Opt.forAll
Opt.fromArray
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)
Same as Opt.map, but also supports arrays.
Opt.map
Similar to Array.map, but also allows omitting elements.
Array.map
mapOpt((x: number) => x > 0 ? opt(x) : none)([-1, 0, 1]) // [1]
Opt.narrow
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.
Opt.orCrash
Opt.orElse
Opt.orElseOpt
Opt.orFalse
Opt.orNaN
Opt.orNull
Opt.orTrue
Opt.orUndef
Opt.print
Opt.prop
Constructs Some. Usually it is opt you are looking for (only in rare cases you want to have for example Some(undefined)).
Some(undefined)
Opt.someOrCrash
Opt.toArray
Same as Opt.zip, but also supports arrays.
Opt.zip
Opt.zip3
Opt.zip4
Opt.zip5
Generated using TypeDoc
Single global instance of None.