default
default:
object
Type Declaration
none: None
The None instance representing absence of value.
Since
2.0.0
some(): <A>(a) => Option<A>
Creates a Some containing the given value.
Type Parameters
A: A
The value type.
a:
A— The value to wrap.
Returns:Option<A>— A Some containing the value.
Since
2.0.0
of(): <A>(a) => Option<A>
Alias for some.
Creates a Some containing the given value.
Type Parameters
A: A
The value type.
a:
A— The value to wrap.
Returns:Option<A>— A Some containing the value.
Since
2.0.0
Since
2.0.0
isSome(): <A>(fa) => fa is Some<A>
Type guard that checks if an Option is a Some.
Type Parameters
A: A
The value type.
fa:
Option<A>— The Option to check.
Returns:fa is Some<A>— True if the Option is a Some.
Since
2.0.0
isNone(): (fa) => fa is None
Type guard that checks if an Option is a None.
fa:
Option<unknown>— The Option to check.
Returns:fa is None— True if the Option is a None.
Since
2.0.0
fromNullable(): <A>(a) => Option<NonNullable<A>>
Creates an Option from a nullable value.
Type Parameters
A: A
The value type.
a:
A— The nullable value.
Returns:Option<NonNullable<A>>— Some if value is not null/undefined, None otherwise.
Since
2.0.0
fromPredicate(): {<A, B>(refinement): (a) => Option<B>; <A>(predicate): (a) => Option<A>; }
Call Signature: > <A, B>(refinement): (a) => Option<B>
Creates an Option from a predicate.
Type Parameters
A: A
The value type.
B: B
refinement:
(a) => a is B— The refinement or predicate function.
Returns:A function that creates an Option based on the predicate.— > (a):Option<B>
Returns:
Option<B>
Since
2.0.0
Call Signature: > <A>(predicate): (a) => Option<A>
Creates an Option from a predicate.
Type Parameters
A: A
The value type.
predicate:
(a) => boolean
Returns:A function that creates an Option based on the predicate.— > (a):Option<A>
Returns:
Option<A>
Since
2.0.0
map(): <A, B>(f) => (fa) => Option<B>
Maps a function over the value of an Option.
Type Parameters
A: A
The input type.
B: B
The output type.
f:
(a) => B— The mapping function.
Returns:A function that transforms the Option.— > (fa):Option<B>
Since
2.0.0
flatMap(): <A, B>(f) => (ma) => Option<B>
Chains a function that returns an Option over the value.
Type Parameters
A: A
The input type.
B: B
The output type.
f:
(a) => Option<B>— The chaining function.
Returns:A function that transforms the Option.— > (ma):Option<B>
Since
2.0.0
chain(): <A, B>(f) => (ma) => Option<B>
Alias for flatMap.
Chains a function that returns an Option over the value.
Type Parameters
A: A
The input type.
B: B
The output type.
f:
(a) => Option<B>— The chaining function.
Returns:A function that transforms the Option.— > (ma):Option<B>
Since
2.0.0
Since
2.0.0
match(): <A, B>(onNone, onSome) => (ma) => B
Pattern matches on an Option.
Type Parameters
A: A
The value type.
B: B
The return type.
onNone:
() => B— Handler for None case.
onSome:(a) => B— Handler for Some case.
Returns:A function that matches the Option.— > (ma):B
ma:
Option<A>
Returns:B
Since
2.0.0
fold(): <A, B>(onNone, onSome) => (ma) => B
Alias for match.
Pattern matches on an Option.
Type Parameters
A: A
The value type.
B: B
The return type.
onNone:
() => B— Handler for None case.
onSome:(a) => B— Handler for Some case.
Returns:A function that matches the Option.— > (ma):B
ma:
Option<A>
Returns:B
Since
2.0.0
Since
2.0.0
matchW(): <B, A, C>(onNone, onSome) => (ma) => B | C
Pattern matches on an Option with widened return types.
Type Parameters
B: B
The return type for None.
A: A
The value type.
C: C
The return type for Some.
onNone:
() => B— Handler for None case.
onSome:(a) => C— Handler for Some case.
Returns:A function that matches the Option.— > (ma):B|C
ma:
Option<A>
Returns:B | C
Since
2.0.0
foldW(): <B, A, C>(onNone, onSome) => (ma) => B | C
Alias for matchW.
Pattern matches on an Option with widened return types.
Type Parameters
B: B
The return type for None.
A: A
The value type.
C: C
The return type for Some.
onNone:
() => B— Handler for None case.
onSome:(a) => C— Handler for Some case.
Returns:A function that matches the Option.— > (ma):B|C
ma:
Option<A>
Returns:B | C
Since
2.0.0
Since
2.0.0
getOrElse(): <A>(onNone) => (ma) => A
Extracts the value from a Some or returns a default.
Type Parameters
A: A
The value type.
onNone:
() => A— Function to provide default value.
Returns:A function that extracts the value.— > (ma):A
ma:
Option<A>
Returns:A
Since
2.0.0
getOrElseW(): <B>(onNone) => <A>(ma) => B | A
Extracts the value from a Some or returns a default with widened type.
Type Parameters
B: B
The default type.
onNone:
() => B— Function to provide default value.
Returns:A function that extracts the value.— > <A>(ma):B|A
Type Parameters
A: A
ma:
Option<A>
Returns:B | A
Since
2.0.0
alt(): <A>(that) => (fa) => Option<A>
Returns an alternative Option if the first is None.
Type Parameters
A: A
The value type.
that:
() => Option<A>— Function to provide alternative Option.
Returns:A function that returns the alternative.— > (fa):Option<A>
Since
2.0.0
orElse(): <A>(that) => (fa) => Option<A>
Alias for alt.
Returns an alternative Option if the first is None.
Type Parameters
A: A
The value type.
that:
() => Option<A>— Function to provide alternative Option.
Returns:A function that returns the alternative.— > (fa):Option<A>
Since
2.0.0
Since
2.0.0
filter(): <A>(predicate) => (fa) => Option<A>
Filters the value with a predicate.
Type Parameters
A: A
The value type.
predicate:
(a) => boolean— The predicate function.
Returns:A function that filters the Option.— > (fa):Option<A>
Since
2.0.0
filterMap(): <A, B>(f) => (fa) => Option<B>
Maps and filters in one operation.
Type Parameters
A: A
The input type.
B: B
The output type.
f:
(a) => Option<B>— The mapping function that returns an Option.
Returns:A function that filterMaps the Option.— > (fa):Option<B>
Since
2.0.0
toNullable(): <A>(ma) => A | null
Converts an Option to a nullable value.
Type Parameters
A: A
The value type.
ma:
Option<A>— The Option to convert.
Returns:A | null— The value or null.
Since
2.0.0
toUndefined(): <A>(ma) => A | undefined
Converts an Option to an undefined value.
Type Parameters
A: A
The value type.
ma:
Option<A>— The Option to convert.
Returns:A | undefined— The value or undefined.
Since
2.0.0
fromEither(): <A>(fa) => Option<A>
Creates an Option from an Either.
Type Parameters
A: A
The value type.
fa:
The Either to convert.— #
_tag:"Left" | "Right"— #
left?:unknown— #
right?:A
Returns:Option<A>— Some if Right, None if Left.
Since
2.0.0
toEither(): <E>(onNone) => <A>(fa) => object
Converts an Option to an Either.
Type Parameters
E: E
The error type.
onNone:
() => E— Function to create error for None.
Returns:A function that converts the Option.— > <A>(fa):object
Type Parameters
A: A
fa:
Option<A>
Returns:object
_tag: > *\_tag*: "Left" | "Right"
left?: E
right?: A
Since
2.0.0
exists(): <A>(predicate) => (ma) => boolean
Tests if a predicate holds for the value.
Type Parameters
A: A
The value type.
predicate:
(a) => boolean— The predicate to test.
Returns:A function that tests the Option.— > (ma):boolean
ma:
Option<A>
Returns:boolean
Since
2.0.0
flatten(): <A>(mma) => Option<A>
Flattens a nested Option.
Type Parameters
A: A
The value type.
mma:
Option<Option<A>>— The nested Option.
Returns:Option<A>— The flattened Option.
Since
2.0.0
compact(): <A>(mma) => Option<A>
Alias for flatten.
Flattens a nested Option.
Type Parameters
A: A
The value type.
mma:
Option<Option<A>>— The nested Option.
Returns:Option<A>— The flattened Option.
Since
2.0.0
Since
2.0.0
apFirst(): (fb) => <A>(fa) => Option<A>
Sequences two Options, keeping the first value.
fb:
Option<unknown>— The second Option.
Returns:A function that sequences the Options.— > <A>(fa):Option<A>
Type Parameters
A: A
Since
2.0.0
apSecond(): <A>(fb) => <B>(fa) => Option<A>
Sequences two Options, keeping the second value.
Type Parameters
A: A
The value type.
fb:
Option<A>— The second Option.
Returns:A function that sequences the Options.— > <B>(fa):Option<A>
Type Parameters
B: B
Since
2.0.0
flap(): <A>(a) => <B>(fab) => Option<B>
Applies a value to a function inside an Option.
Type Parameters
A: A
The input type.
a:
A— The value to apply.
Returns:A function that applies the value.— > <B>(fab):Option<B>
Type Parameters
B: B
Since
2.0.0
as(): <A>(a) => <_>(self) => Option<A>
Replaces the value with a constant.
Type Parameters
A: A
The new value type.
a:
A— The constant value.
Returns:A function that replaces the value.— > <_>(self):Option<A>
Type Parameters
_: _
Since
2.0.0
asUnit(): <_>(self) => Option<void>
Replaces the value with void.
Type Parameters
_: _
self:
Option<_>— The Option to transform.
Returns:Option<void>— An Option containing void.
Since
2.0.0
tryCatch(): <A>(f) => Option<A>
Creates an Option by executing a function that may throw.
Type Parameters
A: A
The value type.
f:
() => A— The function to execute.
Returns:Option<A>— Some if successful, None if throws.
Since
2.0.0
tryCatchK(): <A, B>(f) => (...a) => Option<B>
Lifts a function to return an Option when called.
Type Parameters
A: A extends readonly unknown[]
The argument types.
B: B
The return type.
f:
(...a) => B— The function to lift.
Returns:A lifted function that returns an Option.— > (...a):Option<B>
a:
...A
Returns:Option<B>
Since
2.0.0
fromNullableK(): <A, B>(f) => (...a) => Option<NonNullable<B>>
Lifts a function that may return null/undefined to return an Option.
Type Parameters
A: A extends readonly unknown[]
The argument types.
B: B
The return type.
f:
(...a) => Nullish<B>— The function to lift.
Returns:A lifted function that returns an Option.— > (...a):Option<NonNullable<B>>
a:
...A
Returns:Option<NonNullable<B>>
Since
2.0.0
chainNullableK(): <A, B>(f) => (ma) => Option<NonNullable<B>>
Chains a function that may return null/undefined.
Type Parameters
A: A
The input type.
B: B
The output type.
f:
(a) => Nullish<B>— The chaining function.
Returns:A function that chains the Option.— > (ma):Option<NonNullable<B>>
Since
2.0.0