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 = ""
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)
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)
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)
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!)
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!)
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!))