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 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.
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.
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
.
Contains the None value