We need a whole WithFilter class to honor the "doesn't create a new collection" contract even though it seems unlikely to matter much in a collection with max size 1.
We need a whole WithFilter class to honor the "doesn't create a new collection" contract even though it seems unlikely to matter much in a collection with max size 1.
Returns a scala.Some containing the result of
applying pf
to this scala.Option's contained
value, if this option is
nonempty and pf
is defined for that value.
Returns a scala.Some containing the result of
applying pf
to this scala.Option's contained
value, if this option is
nonempty and pf
is defined for that value.
Returns None
otherwise.
the partial function.
the result of applying pf
to this scala.Option's
value (if possible), or None
.
// Returns Some(HTTP) because the partial function covers the case. Some("http") collect {case "http" => "HTTP"} // Returns None because the partial function doesn't cover the case. Some("ftp") collect {case "http" => "HTTP"} // Returns None because None is passed to the collect method. None collect {case value => value}
Tests whether the option contains a given value as an element.
Tests whether the option contains a given value as an element.
the element to test.
true
if the option has an element that is equal (as
determined by ==
) to elem
, false
otherwise.
// Returns true because Some instance contains string "something" which equals "something". Some("something") contains "something" // Returns false because "something" != "anything". Some("something") contains "anything" // Returns false when method called on None. None contains "anything"
Returns true if this option is nonempty and the predicate
p
returns true when applied to this scala.Option's value.
Returns true if this option is nonempty and the predicate
p
returns true when applied to this scala.Option's value.
Otherwise, returns false.
the predicate to test
Returns this scala.Option if it is nonempty and applying the predicate p
to
this scala.Option's value returns true.
Returns this scala.Option if it is nonempty and applying the predicate p
to
this scala.Option's value returns true. Otherwise, return None
.
the predicate used for testing.
Returns this scala.Option if it is nonempty and applying the predicate p
to
this scala.Option's value returns false.
Returns this scala.Option if it is nonempty and applying the predicate p
to
this scala.Option's value returns false. Otherwise, return None
.
the predicate used for testing.
Returns the result of applying f
to this scala.Option's value if
this scala.Option is nonempty.
Returns the result of applying f
to this scala.Option's value if
this scala.Option is nonempty.
Returns None
if this scala.Option is empty.
Slightly different from map
in that f
is expected to
return an scala.Option (which could be None
).
the function to apply
foreach
map
Returns the result of applying f
to this scala.Option's
value if the scala.Option is nonempty.
Returns the result of applying f
to this scala.Option's
value if the scala.Option is nonempty. Otherwise, evaluates
expression ifEmpty
.
the expression to evaluate if empty.
the function to apply if nonempty.
This is equivalent to scala.Option map f getOrElse ifEmpty
.
Returns true if this option is empty or the predicate
p
returns true when applied to this scala.Option's value.
Returns true if this option is empty or the predicate
p
returns true when applied to this scala.Option's value.
the predicate to test
Apply the given procedure f
to the option's value,
if it is nonempty.
Apply the given procedure f
to the option's value,
if it is nonempty. Otherwise, do nothing.
the procedure to apply.
flatMap
map
Returns the option's value if the option is nonempty, otherwise
return the result of evaluating default
.
Returns the option's value if the option is nonempty, otherwise
return the result of evaluating default
.
the default expression.
Returns true if the option is an instance of scala.Some, false otherwise.
Returns true if the option is an instance of scala.Some, false otherwise.
Returns true if the option is None
, false otherwise.
Returns true if the option is None
, false otherwise.
Returns a singleton iterator returning the scala.Option's value if it is nonempty, or an empty iterator if the option is empty.
Returns a singleton iterator returning the scala.Option's value if it is nonempty, or an empty iterator if the option is empty.
Returns a scala.Some containing the result of applying f
to this scala.Option's
value if this scala.Option is nonempty.
Returns a scala.Some containing the result of applying f
to this scala.Option's
value if this scala.Option is nonempty.
Otherwise return None
.
the function to apply
This is similar to flatMap
except here,
f
does not need to wrap its result in an scala.Option.
foreach
flatMap
Returns false if the option is None
, true otherwise.
Returns false if the option is None
, true otherwise.
Implemented here to avoid the implicit conversion to Iterable.
Returns this scala.Option if it is nonempty,
otherwise return the result of evaluating alternative
.
Returns this scala.Option if it is nonempty,
otherwise return the result of evaluating alternative
.
the alternative expression.
Returns the option's value if it is nonempty,
or null
if it is empty.
Returns the option's value if it is nonempty,
or null
if it is empty.
Although the use of null is discouraged, code written to use
scala.Option must often interface with code that expects and returns nulls.
val initalText: Option[String] = getInitialText val textField = new JComponent(initalText.orNull,20)
Returns a scala.util.Right containing the given
argument right
if this is empty, or
a scala.util.Left containing this scala.Option's value
if this scala.Option is nonempty.
Returns a scala.util.Right containing the given
argument right
if this is empty, or
a scala.util.Left containing this scala.Option's value
if this scala.Option is nonempty.
the expression to evaluate and return if this is empty
toRight
Returns a singleton list containing the scala.Option's value if it is nonempty, or the empty list if the scala.Option is empty.
Returns a singleton list containing the scala.Option's value if it is nonempty, or the empty list if the scala.Option is empty.
Returns a scala.util.Left containing the given
argument left
if this scala.Option is empty, or
a scala.util.Right containing this scala.Option's value if
this is nonempty.
Returns a scala.util.Left containing the given
argument left
if this scala.Option is empty, or
a scala.util.Right containing this scala.Option's value if
this is nonempty.
the expression to evaluate and return if this is empty
toLeft
Necessary to keep scala.Option from being implicitly converted to
scala.collection.Iterable in for
comprehensions.
Necessary to keep scala.Option from being implicitly converted to
scala.collection.Iterable in for
comprehensions.