final class OptionOps[A] extends AnyVal
- Alphabetic
- By Inheritance
- OptionOps
- 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
getClass(): Class[_ <: AnyVal]
- Definition Classes
- AnyVal → Any
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
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)
-
def
orEmpty(implicit A: Monoid[A]): A
If the
Option
is aSome
, return its value.If the
Option
is aSome
, return its value. If theOption
isNone
, return theempty
value forMonoid[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 = ""
-
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)
-
def
toInvalid[B](b: ⇒ B): Validated[A, B]
If the
Option
is aSome
, return its value in a cats.data.Validated.Invalid.If the
Option
is aSome
, return its value in a cats.data.Validated.Invalid. If theOption
isNone
, return the providedB
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)
-
def
toInvalidNec[B](b: ⇒ B): ValidatedNec[A, B]
If the
Option
is aSome
, wrap its value in a cats.data.Chain and return it in a cats.data.Validated.Invalid.If the
Option
is aSome
, wrap its value in a cats.data.Chain and return it in a cats.data.Validated.Invalid. If theOption
isNone
, return the providedB
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)
-
def
toInvalidNel[B](b: ⇒ B): ValidatedNel[A, B]
If the
Option
is aSome
, wrap its value in a cats.data.NonEmptyList and return it in a cats.data.Validated.Invalid.If the
Option
is aSome
, wrap its value in a cats.data.NonEmptyList and return it in a cats.data.Validated.Invalid. If theOption
isNone
, return the providedB
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)
-
def
toLeftIor[B](b: ⇒ B): Ior[A, B]
If the
Option
is aSome
, return its value in a cats.data.Ior.Left.If the
Option
is aSome
, return its value in a cats.data.Ior.Left. If theOption
isNone
, wrap the providedB
value in a cats.data.Ior.RightExample:
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)
-
def
toLeftNec[B](b: ⇒ B): EitherNec[A, B]
If the
Option
is aSome
, wrap its value in a cats.data.NonEmptyChain and return it in a scala.Left.If the
Option
is aSome
, wrap its value in a cats.data.NonEmptyChain and return it in a scala.Left. If theOption
isNone
, return the providedB
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)
-
def
toLeftNel[B](b: ⇒ B): EitherNel[A, B]
If the
Option
is aSome
, wrap its value in a cats.data.NonEmptyList and return it in a scala.Left.If the
Option
is aSome
, wrap its value in a cats.data.NonEmptyList and return it in a scala.Left. If theOption
isNone
, return the providedB
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)
-
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)))
-
def
toRightIor[B](b: ⇒ B): Ior[B, A]
If the
Option
is aSome
, return its value in a cats.data.Ior.Right.If the
Option
is aSome
, return its value in a cats.data.Ior.Right. If theOption
isNone
, wrap the providedB
value in a cats.data.Ior.LeftExample:
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!)
-
def
toRightNec[B](b: ⇒ B): EitherNec[B, A]
If the
Option
is aSome
, return its value in a scala.Right.If the
Option
is aSome
, return its value in a scala.Right. If theOption
isNone
, wrap the providedB
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!))
-
def
toRightNel[B](b: ⇒ B): EitherNel[B, A]
If the
Option
is aSome
, return its value in a scala.Right.If the
Option
is aSome
, return its value in a scala.Right. If theOption
isNone
, wrap the providedB
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!))
-
def
toString(): String
- Definition Classes
- Any
-
def
toValid[B](b: ⇒ B): Validated[B, A]
If the
Option
is aSome
, return its value in a cats.data.Validated.Valid.If the
Option
is aSome
, return its value in a cats.data.Validated.Valid. If theOption
isNone
, return the providedB
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!)
-
def
toValidNec[B](b: ⇒ B): ValidatedNec[B, A]
If the
Option
is aSome
, return its value in a cats.data.Validated.Valid.If the
Option
is aSome
, return its value in a cats.data.Validated.Valid. If theOption
isNone
, wrap the providedB
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!))
-
def
toValidNel[B](b: ⇒ B): ValidatedNel[B, A]
If the
Option
is aSome
, return its value in a cats.data.Validated.Valid.If the
Option
is aSome
, return its value in a cats.data.Validated.Valid. If theOption
isNone
, wrap the providedB
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!))