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