final class OptArg[+A] extends AnyVal with Serializable
OptArg is like Opt except it's intended to be used to type-safely express optional method/constructor
parameters while at the same time avoiding having to explicitly wrap arguments when passing them
(thanks to the implicit conversion from A
to OptArg[A]
). For example:
def takesMaybeString(str: OptArg[String] = OptArg.Empty) = ??? takesMaybeString() // default empty value is used takesMaybeString("string") // no explicit wrapping into OptArg required
Note that like Opt, OptArg assumes its underlying value to be non-null and null
is translated into OptArg.Empty
.
It is strongly recommended that OptArg type is used ONLY in signatures where implicit conversion A => OptArg[A]
is intended to work. You should not use OptArg as a general-purpose "optional value" type - other types like
Opt, NOpt and Option
serve that purpose. For this reason OptArg deliberately does not have any "transforming"
methods like map
, flatMap
, orElse
, etc. Instead it's recommended that OptArg is converted to Opt,
NOpt or Option
as soon as possible (using toOpt
, toNOpt
and toOption
methods).
- Alphabetic
- By Inheritance
- OptArg
- Serializable
- Serializable
- AnyVal
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- Any
-
final
def
##(): Int
- Definition Classes
- Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
boxedOrNull[B >: Null](implicit boxing: Boxing[A, B]): B
- Annotations
- @inline()
-
def
contains[A1 >: A](elem: A1): Boolean
- Annotations
- @inline()
-
def
exists(p: (A) ⇒ Boolean): Boolean
- Annotations
- @inline()
-
def
fold[B](ifEmpty: ⇒ B)(f: (A) ⇒ B): B
- Annotations
- @inline()
-
def
forEmpty(sideEffect: ⇒ Unit): OptArg[A]
Apply side effect only if OptArg is empty.
Apply side effect only if OptArg is empty. It's a bit like foreach for OptArg.Empty
- sideEffect
- code to be executed if optArg is empty
- returns
the same optArg
- Annotations
- @inline()
captionOptArg.forEmpty(logger.warn("caption is empty")).foreach(setCaption)
Example: -
def
forall(p: (A) ⇒ Boolean): Boolean
- Annotations
- @inline()
-
def
foreach[U](f: (A) ⇒ U): Unit
- Annotations
- @inline()
-
def
get: A
- Annotations
- @inline()
-
def
getClass(): Class[_ <: AnyVal]
- Definition Classes
- AnyVal → Any
-
def
getOrElse[B >: A](default: ⇒ B): B
- Annotations
- @inline()
-
def
isDefined: Boolean
- Annotations
- @inline()
-
def
isEmpty: Boolean
- Annotations
- @inline()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
iterator: Iterator[A]
- Annotations
- @inline()
-
def
nonEmpty: Boolean
- Annotations
- @inline()
-
def
orNull[B >: A](implicit ev: <:<[Null, B]): B
- Annotations
- @inline()
-
def
toLeft[X](right: ⇒ X): Either[A, X]
- Annotations
- @inline()
-
def
toList: List[A]
- Annotations
- @inline()
-
def
toNOpt: NOpt[A]
- Annotations
- @inline()
-
def
toOpt: Opt[A]
- Annotations
- @inline()
-
def
toOptRef[B >: Null](implicit boxing: Boxing[A, B]): OptRef[B]
- Annotations
- @inline()
-
def
toOption: Option[A]
- Annotations
- @inline()
-
def
toRight[X](left: ⇒ X): Either[X, A]
- Annotations
- @inline()
-
def
toString(): String
- Definition Classes
- OptArg → Any