Returns the result of applying pf
to this UndefOr's contained
value, if this option is
nonempty and pf
is defined for that value.
Returns the result of applying pf
to this UndefOr's contained
value, if this option is
nonempty and pf
is defined for that value.
Returns undefined otherwise.
the partial function.
the result of applying pf
to this UndefOr's
value (if possible), or undefined.
Returns true if this option is nonempty and the predicate
p
returns true when applied to this UndefOr's value.
Returns true if this option is nonempty and the predicate
p
returns true when applied to this UndefOr's value.
Otherwise, returns false.
the predicate to test
Returns this UndefOr if it is nonempty and applying the predicate p
to
this UndefOr's value returns true.
Returns this UndefOr if it is nonempty and applying the predicate p
to
this UndefOr's value returns true. Otherwise, return undefined.
the predicate used for testing.
Returns this UndefOr if it is nonempty and applying the predicate p
to
this UndefOr's value returns false.
Returns this UndefOr if it is nonempty and applying the predicate p
to
this UndefOr's value returns false. Otherwise, return undefined.
the predicate used for testing.
Returns the result of applying f
to this UndefOr's value if
this UndefOr is nonempty.
Returns the result of applying f
to this UndefOr's value if
this UndefOr is nonempty.
Returns undefined if this UndefOr is empty.
Slightly different from map
in that f
is expected to
return an UndefOr (which could be undefined).
the function to apply
foreach
map
Returns the result of applying f
to this UndefOr's
value if the UndefOr is nonempty.
Returns the result of applying f
to this UndefOr's
value if the UndefOr is nonempty. Otherwise, evaluates
expression ifEmpty
.
the expression to evaluate if empty.
the function to apply if nonempty.
This is equivalent to UndefOr map f getOrElse ifEmpty
.
Returns true if this option is empty or the predicate
p
returns true when applied to this UndefOr's value.
Returns true if this option is empty or the predicate
p
returns true when applied to this UndefOr'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.
Returns the option's value.
java.util.NoSuchElementException
if the option is empty.
The option must be nonEmpty.
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 not undefined
, false otherwise.
Returns true if the option is not undefined
, false otherwise.
Returns true if the option is undefined
, false otherwise.
Returns true if the option is undefined
, false otherwise.
Returns a singleton iterator returning the UndefOr's value if it is nonempty, or an empty iterator if the option is empty.
Returns a singleton iterator returning the UndefOr's value if it is nonempty, or an empty iterator if the option is empty.
Returns the result of applying f
to this UndefOr's
value if this UndefOr is nonempty.
Returns the result of applying f
to this UndefOr's
value if this UndefOr is nonempty.
Otherwise return undefined.
the function to apply
This is similar to flatMap
except here,
f
does not need to wrap its result in an UndefOr.
foreach
flatMap
Returns false if the option is undefined, true otherwise.
Returns false if the option is undefined, true otherwise.
Implemented here to avoid the implicit conversion to Iterable.
Returns this UndefOr if it is nonempty,
otherwise return the result of evaluating alternative
.
Returns this UndefOr 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
UndefOr must often interface with code that expects and returns nulls.
val initalText: Option[String] = getInitialText val textField = new JComponent(initalText.orNull,20)
Returns a Right
containing the given argument right
if this is empty,
or a Left
containing this UndefOr's value if this UndefOr is nonempty.
Returns a Right
containing the given argument right
if this is empty,
or a Left
containing this UndefOr's value if this UndefOr is nonempty.
the expression to evaluate and return if this is empty
toRight
Returns a singleton list containing the UndefOr's value if it is nonempty, or the empty list if the UndefOr is empty.
Returns a singleton list containing the UndefOr's value if it is nonempty, or the empty list if the UndefOr is empty.
Returns a Some
containing this UndefOr's value
if this UndefOr is nonempty, None otherwise.
Returns a Left
containing the given argument left
if this UndefOr is
empty, or a Right
containing this UndefOr's value if this is nonempty.
Returns a Left
containing the given argument left
if this UndefOr is
empty, or a Right
containing this UndefOr's value if this is nonempty.
the expression to evaluate and return if this is empty
toLeft
Necessary to keep UndefOr from being implicitly converted to
scala.collection.Iterable in for
comprehensions.
Necessary to keep UndefOr from being implicitly converted to
scala.collection.Iterable in for
comprehensions.
Value of type A or the JS undefined value.
js.UndefOr[A]
is the type of a value that can be eitherundefined
or anA
. It provides an API similar to that of scala.Option through the UndefOrOps implicit class, whereundefined
take the role of None.By extension, this type is also suited to typing optional fields in native JS types, i.e., fields that may not exist on the object.