The type of the wrapped value
Returns true if both options are Some
and their inner values are equal using
the JavaScript ==
operator, or if both options are None
. If the inner values
are both Option
s or Result
s, then the comparison will be recursive using equals
on the inner values.
Returns the result of calling cases.some()
with the inner value if the option is Some
,
otherwise returns the result of calling cases.none()
.
Returns true if both options are Some
and their inner values are equal using
the JavaScript ===
operator, or if both options are None
. If the inner values
are both Option
s or Result
s, then the comparison will be recursive using strictEquals
on the inner values.
Returns true
if the value is a None
.
true
if the value is a None
, false
otherwise.
Returns true
if the value is a None
or the given function returns true
.
Returns true
if the value is a Some
.
true
if the value is a Some
, false
otherwise.
Returns true
if the value is a Some
and the given function returns true
.
Returns None
if the source option is None
, otherwise returns other
.
Returns None
if the source option is None
, otherwise calls fn
with the inner value and returns the result.
Returns None
if the option is None
, otherwise calls fn
with the inner value and returns:
Some<T>
with the original wrapped value if fn
returns trueNone
if fn
returns falseConverts from Option<Option<T>>
to Option<T>
. Only one level of nesting is removed.
Returns an Option<U>
by mapping the inner value of the source option with fn
.
Returns an option wrapping the provided defaultValue
if the option is None
,
or calls fn
with the inner value and returns a new option wrapping its return value.
Returns an option wrapping the return value of defaultFn
if the option is None
,
or calls mapFn
with the inner value and returns a new option wrapping its return value.
This function is useful for providing a default value that is expensive to compute or has side effects.
The type of the new wrapped value.
A function that returns the default value if the option is None
.
A function that takes the wrapped value and returns a new value.
A new option containing either the default or transformed value.
Converts the Option<T>
into a Result<T, E>
, mapping Some(v)
to Ok(v)
and None
to Err(defaultValue)
.
Converts the Option<T>
into a Result<T, E>
, mapping Some(v)
to Ok(v)
and None
to Err(fn())
.
Returns the source option if it is Some
, otherwise returns other
.
Returns the source option if it is Some
, otherwise calls fn
and returns the result.
This function is useful for providing a default value that is expensive to compute or has side effects.
Returns the source option or other
if exactly one of them is Some
, otherwise returns None
.
Returns the wrapped value. If the option is None
, this will throw an error with the provided message.
Returns the wrapped value. If the option is None
, this will throw an error.
Returns the wrapped value. If the option is None
, this will return the provided default value.
Returns the wrapped value. If the option is None
, this will call the provided function and return its result.
This function is useful for providing a default value that is expensive to compute or has side effects.
All the methods available on
Option<T>
.