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 JsonSome containing the result of
applying pf
to this JsonOption's contained
value, if this option is
nonempty and pf
is defined for that value.
Returns a JsonSome containing the result of
applying pf
to this JsonOption's contained
value, if this option is
nonempty and pf
is defined for that value.
Returns JsonAbsent otherwise.
the partial function.
the result of applying pf
to this JsonOption's
value (if possible), or JsonAbsent.
// 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 JsonOption's value.
Returns true if this option is nonempty and the predicate
p
returns true when applied to this JsonOption's value.
Otherwise, returns false.
the predicate to test
Returns this JsonOption if it is nonempty and applying the predicate p
to
this JsonOption's value returns true.
Returns this JsonOption if it is nonempty and applying the predicate p
to
this JsonOption's value returns true. Otherwise, return JsonAbsent.
the predicate used for testing.
Returns this JsonOption if it is nonempty and applying the predicate p
to
this JsonOption's value returns false.
Returns this JsonOption if it is nonempty and applying the predicate p
to
this JsonOption's value returns false. Otherwise, return JsonAbsent.
the predicate used for testing.
Returns the result of applying f
to this JsonOption's value if
this JsonOption is nonempty.
Returns the result of applying f
to this JsonOption's value if
this JsonOption is nonempty.
Returns JsonAbsent if this JsonOption is empty.
Slightly different from map
in that f
is expected to
return an JsonOption (which could be JsonAbsent).
the function to apply
foreach
map
Returns the result of applying f
to this JsonOption's
value if the JsonOption is nonempty.
Returns the result of applying f
to this JsonOption's
value if the JsonOption is nonempty. Otherwise, evaluates
expression ifEmpty
.
the expression to evaluate if empty.
the function to apply if nonempty.
This is equivalent to JsonOption map f getOrElse ifEmpty
.
Returns true if this option is empty or the predicate
p
returns true when applied to this JsonOption's value.
Returns true if this option is empty or the predicate
p
returns true when applied to this JsonOption'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 maybe's value.
Returns the maybe's value.
java.util.NoSuchElementException
if the maybe is empty
The maybe must be nonEmpty
Returns the maybe's value if the maybe is nonempty, otherwise
return the result of evaluating default
.
Returns the maybe's value if the maybe is nonempty, otherwise
return the result of evaluating default
.
the default expression.
Returns true if maybe is nothing
Returns true if maybe is nothing
Returns true if maybe is instance of just
Returns true if maybe is instance of just
Returns true if maybe is nothing or null
Returns true if maybe is nothing or null
Returns a singleton iterator returning the JsonOption's value if it is nonempty, or an empty iterator if the option is empty.
Returns a singleton iterator returning the JsonOption's value if it is nonempty, or an empty iterator if the option is empty.
Returns a JsonSome containing the result of applying f
to this JsonOption's
value if this JsonOption is nonempty.
Returns a JsonSome containing the result of applying f
to this JsonOption's
value if this JsonOption is nonempty.
Otherwise return JsonAbsent.
the function to apply
This is similar to flatMap
except here,
f
does not need to wrap its result in an JsonOption.
foreach
flatMap
Returns false if the option is JsonAbsent, true otherwise.
Returns false if the option is JsonAbsent, true otherwise.
Implemented here to avoid the implicit conversion to Iterable.
Returns this JsonOption if it is nonempty,
otherwise return the result of evaluating alternative
.
Returns this JsonOption 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
JsonOption must often interface with code that expects and returns nulls.
val initialText: Option[String] = getInitialText val textField = new JComponent(initialText.orNull,20)
Helper function to .orElse JsonSome.
Helper function to .orElse JsonSome. Result is None for JsonNull but for JsonAbsent x param is returned
Returns a scala.util.Right containing the given
argument right
if this is empty, or
a scala.util.Left containing this JsonOption's value
if this JsonOption is nonempty.
Returns a scala.util.Right containing the given
argument right
if this is empty, or
a scala.util.Left containing this JsonOption's value
if this JsonOption is nonempty.
the expression to evaluate and return if this is empty
toRight
Returns a singleton list containing the JsonOption's value if it is nonempty, or the empty list if the JsonOption is empty.
Returns a singleton list containing the JsonOption's value if it is nonempty, or the empty list if the JsonOption is empty.
Turns this JsonOption into scala Option
Turns this JsonOption into scala Option
Returns a scala.util.Left containing the given
argument left
if this JsonOption is empty, or
a scala.util.Right containing this JsonOption's value if
this is nonempty.
Returns a scala.util.Left containing the given
argument left
if this JsonOption is empty, or
a scala.util.Right containing this JsonOption's value if
this is nonempty.
the expression to evaluate and return if this is empty
toLeft
Necessary to keep JsonOption from being implicitly converted to
scala.collection.Iterable in for
comprehensions.
Necessary to keep JsonOption from being implicitly converted to
scala.collection.Iterable in for
comprehensions.
Class
Some[A]
represents existing values of typeA
.