final class Opt[+A] extends AnyVal with Serializable
Like Option
but implemented as value class (avoids boxing) and treats null
as no value.
Therefore, there is no equivalent for Some(null)
.
If you need a value-class version of Option
which differentiates between no value and null
value,
use NOpt.
- Alphabetic
- By Inheritance
- Opt
- 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
boxed[B](implicit boxing: Boxing[A, B]): Opt[B]
- Annotations
- @inline()
-
def
boxedOrNull[B >: Null](implicit boxing: Boxing[A, B]): B
- Annotations
- @inline()
-
def
collect[B](pf: PartialFunction[A, B]): Opt[B]
Analogous to
Option.collect
except that when the function returnsnull
, emptyOpt
is returned as a result.Analogous to
Option.collect
except that when the function returnsnull
, emptyOpt
is returned as a result.- Annotations
- @inline()
-
def
contains[A1 >: A](elem: A1): Boolean
- Annotations
- @inline()
-
def
exists(p: (A) ⇒ Boolean): Boolean
- Annotations
- @inline()
-
def
filter(p: (A) ⇒ Boolean): Opt[A]
- Annotations
- @inline()
-
def
filterNot(p: (A) ⇒ Boolean): Opt[A]
- Annotations
- @inline()
-
def
flatMap[B](f: (A) ⇒ Opt[B]): Opt[B]
- Annotations
- @inline()
-
def
flatten[B](implicit ev: <:<[A, Opt[B]]): Opt[B]
- Annotations
- @inline()
-
def
fold[B](ifEmpty: ⇒ B)(f: (A) ⇒ B): B
- Annotations
- @inline()
-
def
forEmpty(sideEffect: ⇒ Unit): Opt[A]
Apply side effect only if Opt is empty.
Apply side effect only if Opt is empty. It's a bit like foreach for Opt.Empty
- sideEffect
- code to be executed if opt is empty
- returns
the same opt
- Annotations
- @inline()
captionOpt.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
map[B](f: (A) ⇒ B): Opt[B]
Analogous to
Option.map
except that when mapping function returnsnull
, emptyOpt
is returned as a result.Analogous to
Option.map
except that when mapping function returnsnull
, emptyOpt
is returned as a result.- Annotations
- @inline()
-
def
nonEmpty: Boolean
- Annotations
- @inline()
-
def
orElse[B >: A](alternative: ⇒ Opt[B]): Opt[B]
- 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
toOptArg: OptArg[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
- Opt → Any
-
def
unboxed[B](implicit unboxing: Unboxing[B, A]): Opt[B]
- Annotations
- @inline()
-
def
withFilter(p: (A) ⇒ Boolean): WithFilter[A]
- Annotations
- @inline()
-
def
zip[B](that: Opt[B]): Opt[(A, B)]
- Annotations
- @inline()