Packages

final class OptionOps[A] extends AnyVal

Source
option.scala
Linear Supertypes
Type Hierarchy
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 raiseTo[F[_]](implicit F: ApplicativeError[F, A]): F[Unit]

    Raise to an F[Unit], as long as it has an ApplicativeError[F, A] instance If the option is empty, an empty unit effect is given.

    Raise to an F[Unit], as long as it has an ApplicativeError[F, A] instance If the option is empty, an empty unit effect is given. If the option contains an error, it is raised.

    Example:

    scala> import cats.implicits._
    
    scala> type F[A] = Either[String, A]
    
    scala> Option.empty[String].raiseTo[F]
    res0: scala.Either[String, Unit] = Right(())
    
    scala> Option("Failed").raiseTo[F]
    res1: scala.Either[String, Unit] = Left(Failed)
  10. 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)
  11. 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)
  12. 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)
  13. 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)
  14. def toLeftNec[B](b: ⇒ B): EitherNec[A, B]

    If the Option is a Some, wrap its value in a cats.data.NonEmptyChain and return it in a scala.Left.

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

    Example:

    scala> import cats.data.EitherNec
    scala> import cats.implicits._
    
    scala> val error1: Option[String] = Some("error!")
    scala> error1.toLeftNec(3)
    res0: EitherNec[String, Int] = Left(Chain(error!))
    
    scala> val error2: Option[String] = None
    scala> error2.toLeftNec(3)
    res1: EitherNec[String, Int] = Right(3)
  15. def toLeftNel[B](b: ⇒ B): EitherNel[A, B]

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

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

    Example:

    scala> import cats.data.EitherNel
    scala> import cats.implicits._
    
    scala> val error1: Option[String] = Some("error!")
    scala> error1.toLeftNel(3)
    res0: EitherNel[String, Int] = Left(NonEmptyList(error!))
    
    scala> val error2: Option[String] = None
    scala> error2.toLeftNel(3)
    res1: EitherNel[String, Int] = Right(3)
  16. 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)))
  17. 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!)
  18. def toRightNec[B](b: ⇒ B): EitherNec[B, A]

    If the Option is a Some, return its value in a scala.Right.

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

    Example:

    scala> import cats.data.EitherNec
    scala> import cats.implicits._
    
    scala> val result1: Option[Int] = Some(3)
    scala> result1.toRightNec("error!")
    res0: EitherNec[String, Int] = Right(3)
    
    scala> val result2: Option[Int] = None
    scala> result2.toRightNec("error!")
    res1: EitherNec[String, Int] = Left(Chain(error!))
  19. def toRightNel[B](b: ⇒ B): EitherNel[B, A]

    If the Option is a Some, return its value in a scala.Right.

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

    Example:

    scala> import cats.data.EitherNel
    scala> import cats.implicits._
    
    scala> val result1: Option[Int] = Some(3)
    scala> result1.toRightNel("error!")
    res0: EitherNel[String, Int] = Right(3)
    
    scala> val result2: Option[Int] = None
    scala> result2.toRightNel("error!")
    res1: EitherNel[String, Int] = Left(NonEmptyList(error!))
  20. def toString(): String
    Definition Classes
    Any
  21. 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!)
  22. 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!))
  23. 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