syntax
Extensions
Extensions
Returns a $Nullable containing the result of
applying pf
to a Nullable's contained
value, '''if''' a option is
nonempty '''and''' pf
is defined for that value.
Returns $null otherwise.
Returns a $Nullable containing the result of
applying pf
to a Nullable's contained
value, '''if''' a option is
nonempty '''and''' pf
is defined for that value.
Returns $null otherwise.
- Value Params
- pf
the partial function.
- Returns
the result of applying
pf
to a Nullable's value (if possible), or $null.- Example
// Returns Nullable(HTTP) because the partial function covers the case. Nullable("http") collect {case "http" => "HTTP"} // Returns null because the partial function doesn't cover the case. Nullable("ftp") collect {case "http" => "HTTP"} // Returns null because the option is empty. There is no value to pass to the partial function. null 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.
- Value Params
- elem
the element to test.
- Returns
true
if the option has an element that is equal (as determined by==
) toelem
,false
otherwise.- Example
// Returns true because Nullable instance contains string "Nullablething" which equals "Nullablething". Nullable("Nullablething") contains "Nullablething" // Returns false because "Nullablething" != "anything". Nullable("Nullablething") contains "anything" // Returns false when method called on null. null contains "anything"
Returns true if a value is not null '''and''' the predicate $p returns true when applied to the value. Otherwise, returns false.
Returns true if a value is not null '''and''' the predicate $p returns true when applied to the value. Otherwise, returns false.
- Value Params
- p
the predicate to test
Returns a Nullable if it is nonempty '''and''' applying the predicate $p to a Nullable's value returns false. Otherwise, return $null.
Returns a Nullable if it is nonempty '''and''' applying the predicate $p to a Nullable's value returns false. Otherwise, return $null.
- Value Params
- p
the predicate used for testing.
Returns the result of applying $f to a Nullable's
value if the Nullable is nonempty. Otherwise, evaluates
expression ifEmpty
.
Returns the result of applying $f to a Nullable's
value if the Nullable is nonempty. Otherwise, evaluates
expression ifEmpty
.
a is equivalent to:
nullable map f getOrElse ifEmpty
- Value Params
- f
the function to apply if nonempty.
- ifEmpty
the expression to evaluate if empty.
Returns true if a value is null '''or''' the predicate $p returns true when applied to the value.
Returns true if a value is null '''or''' the predicate $p returns true when applied to the value.
- Value Params
- p
the predicate to test
Apply the given procedure $f to the option's value, if it is nonempty. Otherwise, do nothing.
Apply the given procedure $f to the option's value, if it is nonempty. Otherwise, do nothing.
- Value Params
- f
the procedure to apply.
- See also
map
flatMap
Returns the wrapped value,
unless it's null, in which case it returns the result of evaluating default
.
Returns the wrapped value,
unless it's null, in which case it returns the result of evaluating default
.
- Value Params
- default
the default (fallback) expression.
Docs and some of the code below has been adaped from scala.Option whose license is:
Docs and some of the code below has been adaped from scala.Option whose license is:
Scala (https://www.scala-lang.org)
Copyright EPFL and Lightbend, Inc.
Licensed under Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
Returns a singleton iterator returning the Nullable's value if it is nonempty, or an empty iterator if the option is empty.
Returns a singleton iterator returning the Nullable's value if it is nonempty, or an empty iterator if the option is empty.
Returns false if the option is $null, true otherwise.
Returns false if the option is $null, true otherwise.
Returns a Nullable if it is nonempty,
otherwise return the result of evaluating alternative
.
Returns a Nullable if it is nonempty,
otherwise return the result of evaluating alternative
.
- Value Params
- alternative
the alternative expression.
Returns a scala.util.Right containing the given
argument right
if a is empty, or
a scala.util.Left containing a Nullable's value
if a Nullable is nonempty.
Returns a scala.util.Right containing the given
argument right
if a is empty, or
a scala.util.Left containing a Nullable's value
if a Nullable is nonempty.
- Value Params
- right
the expression to evaluate and return if a is empty
- See also
toRight
Returns a singleton list containing the Nullable's value if it is nonempty, or the empty list if the Nullable is empty.
Returns a singleton list containing the Nullable's value if it is nonempty, or the empty list if the Nullable is empty.
Returns a scala.util.Left containing the given
argument left
if a Nullable is empty, or
a scala.util.Right containing a Nullable's value if
a is nonempty.
Returns a scala.util.Left containing the given
argument left
if a Nullable is empty, or
a scala.util.Right containing a Nullable's value if
a is nonempty.
- Value Params
- left
the expression to evaluate and return if a is empty
- See also
toLeft
Converts a Nullable of a pair into a Nullable of the first element and a Nullable of the second element.
Converts a Nullable of a pair into a Nullable of the first element and a Nullable of the second element.
- Type Params
- A1
the type of the first half of the element pair
- A2
the type of the second half of the element pair
- Value Params
- asPair
an implicit conversion which asserts that the element type of a Option is a pair.
- Returns
a pair of Options, containing, respectively, the first and second half of the element pair of a Option.
Converts a Nullable of a triple into three Options, one containing the element from each position of the triple.
Converts a Nullable of a triple into three Options, one containing the element from each position of the triple.
- Type Params
- A1
the type of the first of three elements in the triple
- A2
the type of the second of three elements in the triple
- A3
the type of the third of three elements in the triple
- Value Params
- asTriple
an implicit conversion which asserts that the element type of a Option is a triple.
- Returns
a triple of Options, containing, respectively, the first, second, and third elements from the element triple of a Option.
Returns a $Nullable formed from a option and another option by combining the corresponding elements in a pair. If either of the two options is empty, $null is returned.
Returns a $Nullable formed from a option and another option by combining the corresponding elements in a pair. If either of the two options is empty, $null is returned.
- Value Params
- that
the options which is going to be zipped
- Example
// Returns Nullable(("foo", "bar")) because both options are nonempty. Nullable("foo") zip Nullable("bar") // Returns null because `that` option is empty. Nullable("foo") zip null // Returns null because `a` option is empty. null zip Nullable("bar")