MODULE Option
data
type Option<A> = None<A> | Some<A>
Represents optional values. Instances of Option
are either an instance of Some
or None
The most idiomatic way to use an Option
instance is to treat it as a collection or monad and use map
, flatMap
or
filter
.
(fa: Option<A>): Option<A>
alt
short for alternative, takes another Option
. If this Option
is a Some
type then it will be returned, if it
is a None
then it will return the next Some
if it exist. If both are None
then it will return none
.
For example const someFn = (o: Option<number>) => o.alt(some(4))
someFn(some(2))
will return some(2)
.
someFn(none)
will return some(4)
.
<B>(fab: Option<(a: A) => B>): Option<B>
<B, C>(this: Option<(b: B) => C>, fb: Option<B>): Option<C>
<B>(f: (a: A) => Option<B>): Option<B>
Returns the result of applying f to this Option
's value if this Option
is nonempty. Returns None
if this Option
is empty. Slightly different from map
in that f
is expected to return an Option
(which could be None
)
(S: Setoid<A>, a: A): boolean
Returns true
if the option has an element that is equal (as determined by S
) to a
, false
otherwise
(p: (a: A) => boolean): boolean
Returns true
if this option is non empty and the predicate p
returns true
when applied to this Option's value
<B>(f: (ea: Option<A>) => B): Option<B>
(p: Predicate<A>): Option<A>
Returns this option if it is non empty and the predicate p
return true
when applied to this Option's value.
Otherwise returns None
<B>(b: B, some: (a: A) => B): B
Applies a function to each case in the data structure
<B>(none: () => B, some: (a: A) => B): B
Lazy verion of fold
(a: A): A
Returns the value from this Some
or the given argument if this is a None
(f: () => A): A
Lazy version of getOrElse
(): string
(): this is None<A>
Returns true
if the option is None
, false
otherwise
(): this is Some<A>
Returns true
if the option is an instance of Some
, false
otherwise
<B>(f: (a: A) => B): Option<B>
Takes a function f
and an Option
of A
. Maps f
either on None
or Some
, Option's data constructors. If it maps
on Some
then it will apply the f
on Some
's value, if it maps on None
it will return None
.
<B>(f: (a: A) => B | null | undefined): Option<B>
Maps f
over this Option's value. If the value returned from f
is null or undefined, returns None
<B>(b: B, f: (b: B, a: A) => B): B
(): A | null
Returns the value from this Some
or null
if this is a None
(): string
(): A | undefined
Returns the value from this Some
or undefined
if this is a None
instance
Monad1<URI> &
Foldable1<URI> &
Plus1<URI> &
Traversable1<URI> &
Alternative1<URI> &
Extend1<URI>
function
<L, A>(fa: Either<L, A>): Option<A>
function
<A>(a: A | null | undefined): Option<A>
Constructs a new Option
from a nullable type. If the value is null
or undefined
, returns None
, otherwise returns
the value wrapped in a Some
function
<A>(predicate: Predicate<A>) => (a: A): Option<A>
function
<A = never>(): Monoid<Option<A>>
Option monoid returning the left-most non-None value
function
<A = never>(): Monoid<Option<A>>
Option monoid returning the right-most non-None value
function
<A>(S: Semigroup<A>): Monoid<Option<A>>
function
<A>(S: Setoid<A>): Setoid<Option<A>>
function
<A>(fa: Option<A>): fa is None<A>
Returns true
if the option is None
, false
otherwise
function
<A>(fa: Option<A>): fa is Some<A>
Returns true
if the option is an instance of Some
, false
otherwise
function Alias of
of
function
<A>(f: Lazy<A>): Option<A>