Class/Object

com.avsystem.commons.misc

OptArg

Related Docs: object OptArg | package misc

Permalink

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).

Linear Supertypes
Serializable, Serializable, AnyVal, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. OptArg
  2. Serializable
  3. Serializable
  4. AnyVal
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def contains[A1 >: A](elem: A1): Boolean

    Permalink
    Annotations
    @inline()
  6. def exists(p: (A) ⇒ Boolean): Boolean

    Permalink
    Annotations
    @inline()
  7. def fold[B](ifEmpty: ⇒ B)(f: (A) ⇒ B): B

    Permalink
    Annotations
    @inline()
  8. def forEmpty(sideEffect: ⇒ Unit): OptArg[A]

    Permalink

    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()
    Example:
    1. captionOptArg.forEmpty(logger.warn("caption is empty")).foreach(setCaption)
  9. def forall(p: (A) ⇒ Boolean): Boolean

    Permalink
    Annotations
    @inline()
  10. def foreach[U](f: (A) ⇒ U): Unit

    Permalink
    Annotations
    @inline()
  11. def get: A

    Permalink
    Annotations
    @inline()
  12. def getClass(): Class[_ <: AnyVal]

    Permalink
    Definition Classes
    AnyVal → Any
  13. def getOrElse[B >: A](default: ⇒ B): B

    Permalink
    Annotations
    @inline()
  14. def isDefined: Boolean

    Permalink
    Annotations
    @inline()
  15. def isEmpty: Boolean

    Permalink
    Annotations
    @inline()
  16. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  17. def iterator: Iterator[A]

    Permalink
    Annotations
    @inline()
  18. def nonEmpty: Boolean

    Permalink
    Annotations
    @inline()
  19. def orNull[B >: A](implicit ev: <:<[Null, B]): B

    Permalink
    Annotations
    @inline()
  20. def toLeft[X](right: ⇒ X): Either[A, X]

    Permalink
    Annotations
    @inline()
  21. def toList: List[A]

    Permalink
    Annotations
    @inline()
  22. def toNOpt: NOpt[A]

    Permalink
    Annotations
    @inline()
  23. def toOpt: Opt[A]

    Permalink
    Annotations
    @inline()
  24. def toOptRef[B >: Null](implicit boxing: Boxing[A, B]): OptRef[B]

    Permalink
    Annotations
    @inline()
  25. def toOption: Option[A]

    Permalink
    Annotations
    @inline()
  26. def toRight[X](left: ⇒ X): Either[X, A]

    Permalink
    Annotations
    @inline()
  27. def toString(): String

    Permalink
    Definition Classes
    OptArg → Any

Inherited from Serializable

Inherited from Serializable

Inherited from AnyVal

Inherited from Any

Ungrouped