Returns the contained Some
value, if exists. Throws an error if not.
If you know you're dealing with Some
and the compiler knows it too (because you tested
isSome()
or isNone()
) you should use value
instead. While Some
's expect()
and value
will
both return the same value using value
is preferable because it makes it clear that
there won't be an exception thrown on access.
the message to throw if no Some value.
Maps an Option<T>
to Option<U>
by applying a function to a contained Some
value,
leaving a None
value untouched.
This function can be used to compose the Options of two functions.
Maps an Option<T>
to Option<U>
by either converting T
to U
using mapper
(in case
of Some
) or using the default_
value (in case of None
).
If default
is a result of a function call consider using mapOrElse()
instead, it will
only evaluate the function when needed.
Maps an Option<T>
to Option<U>
by either converting T
to U
using mapper
(in case
of Some
) or producing a default value using the default
function (in case of None
).
Returns Some()
if we have a value, otherwise returns other
.
other
is evaluated eagerly. If other
is a result of a function
call try orElse()
instead – it evaluates the parameter lazily.
Some(1).or(Some(2)) // => Some(1)
None.or(Some(2)) // => Some(2)
Returns the contained Some
value, but never throws.
Unlike unwrap()
, this method doesn't throw and is only callable on an Some
Therefore, it can be used instead of unwrap()
as a maintainability safeguard
that will fail to compile if the type of the Option is later changed to a None that can actually occur.
(this is the into_Some()
in rust)
Returns the contained Some
value.
Because this function may throw, its use is generally discouraged.
Instead, prefer to handle the None
case explicitly.
If you know you're dealing with Some
and the compiler knows it too (because you tested
isSome()
or isNone()
) you should use value
instead. While Some
's unwrap()
and value
will
both return the same value using value
is preferable because it makes it clear that
there won't be an exception thrown on access.
Throws if the value is None
.
Readonly
valueStatic
EMPTY
Contains the success value