Returns None
if the Option
is None
, otherwise calls predicate with the wrapped value and returns:
Some(t)
if predicate returns true
(where t
is the wrapped value with inferred new type), andNone
if predicate returns false
.Returns None
if the Option
is None
, otherwise calls predicate with the wrapped value and returns:
Some(t)
if predicate returns true
(where t
is the wrapped value), andNone
if predicate returns false
.A function that returns true
or false
.
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined
is used instead.
Converts from Option<Option<T>>
to Option<T>
A function that returns true
if the value satisfies the predicate, otherwise false
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined
is used instead.
true
if the Option
is a Some
and and the value inside of it matches a predicate.
Transforms the Option<T>
into a Result<T, E>
, mapping Some(v)
to Ok(v)
and None to Err(err)
.
Arguments passed to okOr
are eagerly evaluated; if you are passing the result of a function call, it is recommended to use okOrElse
, which is lazily evaluated.
The error value for Err
if the Option
is None
.
Transforms the Option<T>
into a Result<T, E>
, mapping Some(v)
to Ok(v)
and None
to Err(err())
.
A function that returns the error value for Err
if the Option
is None
.
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined
is used instead.
Transposes an Option(Result)
into Result(Option)
.
None
will be mapped to Ok(None)
.Some(Ok(_))
and Some(Err(_))
will be mapped to Ok(Some(_))
and Err(_)
.Some(value)
will be mapped to Ok(Some(value))
.the contained Some
value or undefined
otherwise.
Arguments passed to unwrapOr
are eagerly evaluated; if you are passing the result of a function call, it is recommended to use unwrapOrElse
, which is lazily evaluated.
default value
the contained Some
value or a provided default.
Arguments passed to unwrapOr
are eagerly evaluated; if you are passing the result of a function call, it is recommended to use unwrapOrElse
, which is lazily evaluated.
A function that computes a default value.
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined
is used instead.
the contained Some
value or computes it from a closure.
Unzips an Option
containing a tuple of two Option
s.
[Some(a), Some(b)]
if this
is Some([a, b])
, otherwise [None, None]
.
Static
fromWrap a value in an Option
if the value is truthy.
A value of type T
Wrap a value in an Option
if the value satisfies the predicate.
Source value
A function that returns true
if the value satisfies the predicate, otherwise false
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined
is used instead.
Wrap a value in an Option
if the value satisfies the predicate.
Static
isStatic
isStatic
SomeStatic
unwrap
The
Option
type is an immutable representation of an optional value: everyOption
is eitherSome
and contains a value, orNone
and does not.