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.syntax.option._ scala> import cats.std.string._ 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.syntax.option._ 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.syntax.option._ scala> val error1: Option[String] = Some("error!") scala> error1.toInvalidNel(3) res0: ValidatedNel[String, Int] = Invalid(OneAnd(error!,List())) 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.Xor.Left.
If the Option
is a Some
, return its value in a cats.data.Xor.Left.
If the Option
is None
, return the provided B
value in a
cats.data.Xor.Right.
Example:
scala> import cats.data.Xor scala> import cats.syntax.option._ scala> val error1: Option[String] = Some("error!") scala> error1.toLeftXor(3) res0: String Xor Int = Left(error!) scala> val error2: Option[String] = None scala> error2.toLeftXor(3) res1: String Xor Int = Right(3)
If the Option
is a Some
, return its value in a cats.data.Xor.Right.
If the Option
is a Some
, return its value in a cats.data.Xor.Right.
If the Option
is None
, return the provided B
value in a
cats.data.Xor.Left.
Example:
scala> import cats.data.Xor scala> import cats.syntax.option._ scala> val result1: Option[Int] = Some(3) scala> result1.toRightXor("error!") res0: String Xor Int = Right(3) scala> val result2: Option[Int] = None scala> result2.toRightXor("error!") res1: String Xor 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.syntax.option._ 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.syntax.option._ 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(OneAnd(error!,List()))