Skip to main content

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>

fa: Option<A>
Returns: 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>

ma: Option<A>
Returns: 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>

ma: Option<A>
Returns: 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>

fa: Option<A>
Returns: 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>

fa: Option<A>
Returns: 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>

fa: Option<A>
Returns: 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>

fa: Option<A>
Returns: 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​

fa: Option<A>
Returns: Option<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​

fa: Option<B>
Returns: Option<A>

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​

fab: Option<(a) => B>
Returns: Option<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​

_: _​

self: Option<_>
Returns: Option<A>

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>>

ma: Option<A>
Returns: Option<NonNullable<B>>

Since​

2.0.0