Class

cats.syntax

OptionOps

Related Doc: package syntax

Permalink

final class OptionOps[A] extends AnyVal

Linear Supertypes
AnyVal, Any
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])

    Permalink

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def getClass(): Class[_ <: AnyVal]

    Permalink
    Definition Classes
    AnyVal → Any
  6. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  7. val oa: Option[A]

    Permalink
  8. def orEmpty(implicit A: Monoid[A]): A

    Permalink

    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 = ""
  9. def toInvalid[B](b: ⇒ B): Validated[A, B]

    Permalink

    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)
  10. def toInvalidNel[B](b: ⇒ B): ValidatedNel[A, B]

    Permalink

    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)
  11. def toLeftXor[B](b: ⇒ B): Xor[A, B]

    Permalink

    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)
  12. def toRightXor[B](b: ⇒ B): Xor[B, A]

    Permalink

    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!)
  13. def toString(): String

    Permalink
    Definition Classes
    Any
  14. def toValid[B](b: ⇒ B): Validated[B, A]

    Permalink

    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!)
  15. def toValidNel[B](b: ⇒ B): ValidatedNel[B, A]

    Permalink

    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()))

Inherited from AnyVal

Inherited from Any

Ungrouped