results-ts / OptionMethods
Interface: OptionMethods<T>
Defined in: option.ts:43
Type Parameters
T
T
Methods
and()
Call Signature
and<
U>(optb):Option<U>
Defined in: option.ts:157
Returns None if the option is None, otherwise returns optb.
Type Parameters
U
U
Parameters
optb
Option<U>
Returns
Option<U>
Call Signature
and<
U>(optb):AsyncOption<U>
Defined in: option.ts:158
Type Parameters
U
U
Parameters
optb
PromiseLike<Option<U>>
Returns
AsyncOption<U>
Call Signature
and<
U>(optb):Option<U> |AsyncOption<U>
Defined in: option.ts:159
Type Parameters
U
U
Parameters
optb
Option<U> | PromiseLike<Option<U>>
Returns
Option<U> | AsyncOption<U>
andThen()
andThen<
U>(f):Option<U>
Defined in: option.ts:166
Returns None if the option is None, otherwise calls f with the wrapped value and returns the result.
Type Parameters
U
U
Parameters
f
(val) => Option<U>
Returns
Option<U>
andThenAsync()
andThenAsync<
U>(f):AsyncOption<U>
Defined in: option.ts:171
Async version of andThen. Returns None if the option is None, otherwise calls async f with the wrapped value and returns the result.
Type Parameters
U
U
Parameters
f
(val) => PromiseLike<Option<U>>
Returns
AsyncOption<U>
expect()
expect(
msg):T
Defined in: option.ts:72
Returns the contained Some value.
Parameters
msg
string
Returns
T
Throws
PanicError with msg on None.
filter()
filter(
predicate):Option<T>
Defined in: option.ts:178
Returns None if the option is None, otherwise calls predicate with the wrapped value and returns:
Some(t)ifpredicatereturnstrue(wheretis the wrapped value), andNoneifpredicatereturnsfalse.
Parameters
predicate
(val) => boolean
Returns
Option<T>
filterAsync()
filterAsync(
predicate):AsyncOption<T>
Defined in: option.ts:185
Async version of filter. Returns None if the option is None, otherwise calls async predicate with the wrapped value and returns:
Some(t)ifpredicateresolves totrue(wheretis the wrapped value), andNoneifpredicateresolves tofalse.
Parameters
predicate
(val) => PromiseLike<boolean>
Returns
AsyncOption<T>
flatten()
flatten<
U>(this):Option<U>
Defined in: option.ts:255
Converts from Option<Option<T>> to Option<T>.
Type Parameters
U
U
Parameters
this
Returns
Option<U>
Throws
FlattenError if a Some value is not an Option.
getOrInsert()
getOrInsert(
value):T
Defined in: option.ts:223
Inserts value into the option if it is None, then returns a reference to the contained value.
Parameters
value
T
Returns
T
getOrInsertWith()
getOrInsertWith(
f):T
Defined in: option.ts:228
Inserts a value computed from f into the option if it is None, then returns a reference to the contained value.
Parameters
f
() => T
Returns
T
getOrInsertWithAsync()
getOrInsertWithAsync(
f):Promise<T>
Defined in: option.ts:233
Async version of getOrInsertWith. Inserts a value computed from async f into the option if it is None, then returns a reference to the contained value.
Parameters
f
() => PromiseLike<T>
Returns
Promise<T>
insert()
insert(
value):T
Defined in: option.ts:218
Inserts value into the option, then returns a reference to it.
Parameters
value
T
Returns
T
inspect()
inspect(
f):Option<T>
Defined in: option.ts:109
Calls f with the Some value and returns the original option.
Parameters
f
(val) => void
Returns
Option<T>
inspectAsync()
inspectAsync(
f):AsyncOption<T>
Defined in: option.ts:114
Awaits f with the Some value and returns the original option.
Parameters
f
(val) => PromiseLike<void>
Returns
AsyncOption<T>
isNone()
isNone():
this is NoneOption<T>
Defined in: option.ts:60
Returns true if the option is a None value.
Returns
this is NoneOption<T>
isNoneOr()
isNoneOr(
f):boolean
Defined in: option.ts:65
Returns true if the option is a None or its value matches the predicate.
Parameters
f
(val) => boolean
Returns
boolean
isSome()
isSome():
this is SomeOption<T>
Defined in: option.ts:49
Returns true if the option is a Some value.
Returns
this is SomeOption<T>
isSomeAnd()
Call Signature
isSomeAnd<
U>(f):this is SomeOption<U>
Defined in: option.ts:54
Returns true if the option is a Some and its value matches the predicate.
Type Parameters
U
U
Parameters
f
(val) => val is U
Returns
this is SomeOption<U>
Call Signature
isSomeAnd(
f):this is SomeOption<T>
Defined in: option.ts:55
Parameters
f
(val) => boolean
Returns
this is SomeOption<T>
iter()
iter():
IterableIterator<T>
Defined in: option.ts:152
Returns an iterator over the contained value, or an empty iterator if absent.
Returns
IterableIterator<T>
map()
map<
U>(f):Option<U>
Defined in: option.ts:99
Maps an Option<T> to Option<U> by applying a function to a contained value.
Type Parameters
U
U
Parameters
f
(val) => U
Returns
Option<U>
mapAsync()
mapAsync<
U>(f):AsyncOption<U>
Defined in: option.ts:104
Async version of map. Maps an Option<T> to AsyncOption<U> by applying an async function to a contained value.
Type Parameters
U
U
Parameters
f
(val) => PromiseLike<U>
Returns
AsyncOption<U>
mapOr()
mapOr<
U>(defaultVal,f):U
Defined in: option.ts:119
Returns the fallback on None, or calls f with the Some value.
Type Parameters
U
U
Parameters
defaultVal
U
f
(val) => U
Returns
U
mapOrElse()
mapOrElse<
U>(defaultF,f):U
Defined in: option.ts:124
Calls defaultF on None, or calls f with the Some value.
Type Parameters
U
U
Parameters
defaultF
() => U
f
(val) => U
Returns
U
mapOrElseAsync()
mapOrElseAsync<
U>(defaultF,f):Promise<U>
Defined in: option.ts:129
Awaits defaultF on None, or awaits f with the Some value.
Type Parameters
U
U
Parameters
defaultF
() => PromiseLike<U>
f
(val) => PromiseLike<U>
Returns
Promise<U>
match()
match<
U>(handlers):U
Defined in: option.ts:288
Matches the Option with two functions, one for each variant.
Type Parameters
U
U
Parameters
handlers
None
() => U
Some
(val) => U
Returns
U
okOr()
okOr<
E>(err):Result<T,E>
Defined in: option.ts:137
Transforms the Option<T> into a Result<T, E>, mapping Some(v) to Ok(v) and None to Err(err).
Type Parameters
E
E
Parameters
err
E
Returns
Result<T, E>
okOrElse()
okOrElse<
E>(errF):Result<T,E>
Defined in: option.ts:142
Transforms the Option<T> into a Result<T, E>, mapping Some(v) to Ok(v) and None to Err(err()).
Type Parameters
E
E
Parameters
errF
() => E
Returns
Result<T, E>
okOrElseAsync()
okOrElseAsync<
E>(errF):AsyncResult<T,E>
Defined in: option.ts:147
Async version of okOrElse. Converts the Option<T> to an AsyncResult<T, E>, mapping Some(v) to Ok(v) and None to Err(await errF()).
Type Parameters
E
E
Parameters
errF
() => PromiseLike<E>
Returns
AsyncResult<T, E>
or()
Call Signature
or<
T2>(optb):Option<T|T2>
Defined in: option.ts:190
Returns the option if it contains a value, otherwise returns optb.
Type Parameters
T2
T2
Parameters
optb
Option<T2>
Returns
Option<T | T2>
Call Signature
or<
T2>(optb):AsyncOption<T|T2>
Defined in: option.ts:191
Type Parameters
T2
T2
Parameters
optb
PromiseLike<Option<T2>>
Returns
AsyncOption<T | T2>
Call Signature
or<
T2>(optb):Option<T|T2> |AsyncOption<T|T2>
Defined in: option.ts:192
Type Parameters
T2
T2
Parameters
optb
Option<T2> | PromiseLike<Option<T2>>
Returns
Option<T | T2> | AsyncOption<T | T2>
orElse()
orElse<
T2>(f):Option<T|T2>
Defined in: option.ts:199
Returns the option if it contains a value, otherwise calls f and returns the result.
Type Parameters
T2
T2
Parameters
f
() => Option<T2>
Returns
Option<T | T2>
orElseAsync()
orElseAsync<
T2>(f):AsyncOption<T|T2>
Defined in: option.ts:204
Async version of orElse. Returns the option if it contains a value, otherwise calls async f and returns the result.
Type Parameters
T2
T2
Parameters
f
() => PromiseLike<Option<T2>>
Returns
AsyncOption<T | T2>
replace()
replace(
value):Option<T>
Defined in: option.ts:248
Sets the option to Some(value) and returns its previous state as an Option.
Parameters
value
T
Returns
Option<T>
take()
take():
Option<T>
Defined in: option.ts:238
Takes the value out of the option, leaving a None in its place.
Returns
Option<T>
takeIf()
takeIf(
predicate):Option<T>
Defined in: option.ts:243
Takes the value out of the option, but only if the predicate evaluates to true on the value.
Parameters
predicate
(val) => boolean
Returns
Option<T>
toString()
toString():
string
Defined in: option.ts:44
Returns
string
transpose()
Defined in: option.ts:265
Transposes an Option of a Result into a Result of an Option.
Converts Some(Ok(value)) to Ok(Some(value)), Some(Err(error)) to Err(error), and None to Ok(None).
Type Parameters
T
T
E
E
Parameters
this
Returns
Throws
TransposeError if a Some value is not a Result.
unwrap()
unwrap():
T
Defined in: option.ts:79
Returns the contained Some value.
Returns
T
Throws
PanicError on None.
unwrapOr()
unwrapOr(
defaultVal):T
Defined in: option.ts:84
Returns the contained Some value or a provided default.
Parameters
defaultVal
T
Returns
T
unwrapOrElse()
unwrapOrElse(
f):T
Defined in: option.ts:89
Returns the contained Some value, or calls f on None.
Parameters
f
() => T
Returns
T
unwrapOrElseAsync()
unwrapOrElseAsync(
f):Promise<T>
Defined in: option.ts:94
Returns the Some value, or awaits f on None.
Parameters
f
() => PromiseLike<T>
Returns
Promise<T>
unzip()
Defined in: option.ts:283
Unzips an Option containing a tuple of two values.
Returns [Some(a), Some(b)] for Some([a, b]), or [None, None] for None.
Type Parameters
T
T
U
U
Parameters
this
Option<[T, U]>
Returns
xor()
Call Signature
xor<
T2>(optb):Option<T|T2>
Defined in: option.ts:209
Returns Some if exactly one of this, optb is Some, otherwise returns None.
Type Parameters
T2
T2
Parameters
optb
Option<T2>
Returns
Option<T | T2>
Call Signature
xor<
T2>(optb):AsyncOption<T|T2>
Defined in: option.ts:210
Type Parameters
T2
T2
Parameters
optb
PromiseLike<Option<T2>>
Returns
AsyncOption<T | T2>
Call Signature
xor<
T2>(optb):Option<T|T2> |AsyncOption<T|T2>
Defined in: option.ts:211
Type Parameters
T2
T2
Parameters
optb
Option<T2> | PromiseLike<Option<T2>>
Returns
Option<T | T2> | AsyncOption<T | T2>
zip()
Call Signature
zip<
U>(other):Option<[T,U]>
Defined in: option.ts:272
Combines two options into an option containing a tuple of their values.
Returns Some([a, b]) if both options are Some, otherwise returns None.
Type Parameters
U
U
Parameters
other
Option<U>
Returns
Option<[T, U]>
Call Signature
zip<
U>(other):AsyncOption<[T,U]>
Defined in: option.ts:273
Type Parameters
U
U
Parameters
other
PromiseLike<Option<U>>
Returns
AsyncOption<[T, U]>
Call Signature
zip<
U>(other):Option<[T,U]> |AsyncOption<[T,U]>
Defined in: option.ts:274
Type Parameters
U
U
Parameters
other
Option<U> | PromiseLike<Option<U>>
Returns
Option<[T, U]> | AsyncOption<[T, U]>