Packages

final class OptionOps[A] extends AnyVal

Source
option.scala
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. OptionOps
  2. AnyVal
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new OptionOps(oa: Option[A])

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    Any
  2. final def ##(): Int
    Definition Classes
    Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def getClass(): Class[_ <: AnyVal]
    Definition Classes
    AnyVal → Any
  6. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  7. def liftTo[F[_]]: LiftToPartiallyApplied[F, A]

    Lift to a F[A] as long as it has an ApplicativeError[F] instance

    Lift to a F[A] as long as it has an ApplicativeError[F] instance

    Example:

    scala> import cats.implicits._
    scala> Some(1).liftTo[Either[CharSequence, ?]]("Empty")
    res0: scala.Either[CharSequence, Int] = Right(1)
    
    scala> Option.empty[Int].liftTo[Either[CharSequence, ?]]("Empty")
    res1: scala.Either[CharSequence, Int] = Left(Empty)
  8. def orEmpty(implicit A: Monoid[A]): A

    If the Option is a Some, return its value.

    If the Option is a Some, return its value. If the Option is None, return the empty value for Monoid[A].

    Example:

    scala> import cats.implicits._
    
    scala> val someString: Option[String] = Some("hello")
    scala> someString.orEmpty
    res0: String = hello
    
    scala> val noneString: Option[String] = None
    scala> noneString.orEmpty
    res1: String = ""
  9. def toInvalid[B](b: ⇒ B): Validated[A, B]

    If the Option is a Some, return its value in a cats.data.Validated.Invalid.

    If the Option is a Some, return its value in a cats.data.Validated.Invalid. If the Option is None, return the provided B value in a cats.data.Validated.Valid.

    Example:

    scala> import cats.data.Validated
    scala> import cats.implicits._
    
    scala> val error1: Option[String] = Some("error!")
    scala> error1.toInvalid(3)
    res0: Validated[String, Int] = Invalid(error!)
    
    scala> val error2: Option[String] = None
    scala> error2.toInvalid(3)
    res1: Validated[String, Int] = Valid(3)
  10. def toInvalidNec[B](b: ⇒ B): ValidatedNec[A, B]

    If the Option is a Some, wrap its value in a cats.data.Chain and return it in a cats.data.Validated.Invalid.

    If the Option is a Some, wrap its value in a cats.data.Chain and return it in a cats.data.Validated.Invalid. If the Option is None, return the provided B value in a cats.data.Validated.Valid.

    Example:

    scala> import cats.data.ValidatedNec
    scala> import cats.implicits._
    
    scala> val error1: Option[String] = Some("error!")
    scala> error1.toInvalidNec(3)
    res0: ValidatedNec[String, Int] = Invalid(Chain(error!))
    
    scala> val error2: Option[String] = None
    scala> error2.toInvalidNec(3)
    res1: ValidatedNec[String, Int] = Valid(3)
  11. def toInvalidNel[B](b: ⇒ B): ValidatedNel[A, B]

    If the Option is a Some, wrap its value in a cats.data.NonEmptyList and return it in a cats.data.Validated.Invalid.

    If the Option is a Some, wrap its value in a cats.data.NonEmptyList and return it in a cats.data.Validated.Invalid. If the Option is None, return the provided B value in a cats.data.Validated.Valid.

    Example:

    scala> import cats.data.ValidatedNel
    scala> import cats.implicits._
    
    scala> val error1: Option[String] = Some("error!")
    scala> error1.toInvalidNel(3)
    res0: ValidatedNel[String, Int] = Invalid(NonEmptyList(error!))
    
    scala> val error2: Option[String] = None
    scala> error2.toInvalidNel(3)
    res1: ValidatedNel[String, Int] = Valid(3)
  12. def toLeftIor[B](b: ⇒ B): Ior[A, B]

    If the Option is a Some, return its value in a cats.data.Ior.Left.

    If the Option is a Some, return its value in a cats.data.Ior.Left. If the Option is None, wrap the provided B value in a cats.data.Ior.Right

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> val result1: Option[String] = Some("error!")
    scala> result1.toLeftIor(3)
    res0: Ior[String, Int] = Left(error!)
    
    scala> val result2: Option[String] = None
    scala> result2.toLeftIor(3)
    res1: Ior[String, Int] = Right(3)
  13. def toOptionT[F[_]](implicit arg0: Applicative[F]): OptionT[F, A]

    Transform the Option into a cats.data.OptionT while lifting it into the specified Applicative.

    Transform the Option into a cats.data.OptionT while lifting it into the specified Applicative.

    scala> import cats.implicits._
    scala> val op: Option[Int] = Some(3)
    scala> op.toOptionT[List]
    res0: cats.data.OptionT[List, Int] = OptionT(List(Some(3)))
  14. def toRightIor[B](b: ⇒ B): Ior[B, A]

    If the Option is a Some, return its value in a cats.data.Ior.Right.

    If the Option is a Some, return its value in a cats.data.Ior.Right. If the Option is None, wrap the provided B value in a cats.data.Ior.Left

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> val result1: Option[Int] = Some(3)
    scala> result1.toRightIor("error!")
    res0: Ior[String, Int] = Right(3)
    
    scala> val result2: Option[Int] = None
    scala> result2.toRightIor("error!")
    res1: Ior[String, Int] = Left(error!)
  15. def toString(): String
    Definition Classes
    Any
  16. def toValid[B](b: ⇒ B): Validated[B, A]

    If the Option is a Some, return its value in a cats.data.Validated.Valid.

    If the Option is a Some, return its value in a cats.data.Validated.Valid. If the Option is None, return the provided B value in a cats.data.Validated.Invalid.

    Example:

    scala> import cats.data.Validated
    scala> import cats.implicits._
    
    scala> val result1: Option[Int] = Some(3)
    scala> result1.toValid("error!")
    res0: Validated[String, Int] = Valid(3)
    
    scala> val result2: Option[Int] = None
    scala> result2.toValid("error!")
    res1: Validated[String, Int] = Invalid(error!)
  17. def toValidNec[B](b: ⇒ B): ValidatedNec[B, A]

    If the Option is a Some, return its value in a cats.data.Validated.Valid.

    If the Option is a Some, return its value in a cats.data.Validated.Valid. If the Option is None, wrap the provided B value in a cats.data.Chain and return the result in a cats.data.Validated.Invalid.

    Example:

    scala> import cats.data.ValidatedNec
    scala> import cats.implicits._
    
    scala> val result1: Option[Int] = Some(3)
    scala> result1.toValidNec("error!")
    res0: ValidatedNec[String, Int] = Valid(3)
    
    scala> val result2: Option[Int] = None
    scala> result2.toValidNec("error!")
    res1: ValidatedNec[String, Int] = Invalid(Chain(error!))
  18. def toValidNel[B](b: ⇒ B): ValidatedNel[B, A]

    If the Option is a Some, return its value in a cats.data.Validated.Valid.

    If the Option is a Some, return its value in a cats.data.Validated.Valid. If the Option is None, wrap the provided B value in a cats.data.NonEmptyList and return the result in a cats.data.Validated.Invalid.

    Example:

    scala> import cats.data.ValidatedNel
    scala> import cats.implicits._
    
    scala> val result1: Option[Int] = Some(3)
    scala> result1.toValidNel("error!")
    res0: ValidatedNel[String, Int] = Valid(3)
    
    scala> val result2: Option[Int] = None
    scala> result2.toValidNel("error!")
    res1: ValidatedNel[String, Int] = Invalid(NonEmptyList(error!))

Inherited from AnyVal

Inherited from Any

Ungrouped