Class/Object

scalaz

\/

Related Docs: object \/ | package scalaz

Permalink

sealed abstract class \/[+A, +B] extends Product with Serializable

Represents a disjunction: a result that is either an A or a B.

An instance of A \/ B is either a -\/[A] (aka a "left") or a \/-[B] (aka a "right").

A common use of a disjunction is to explicitly represent the possibility of failure in a result as opposed to throwing an exception. By convention, the left is used for errors and the right is reserved for successes. For example, a function that attempts to parse an integer from a string may have a return type of NumberFormatException \/ Int. However, since there is no need to actually throw an exception, the type (A) chosen for the "left" could be any type representing an error and has no need to actually extend Exception.

A \/ B is isomorphic to scala.Either[A, B], but \/ is right-biased, so methods such as map and flatMap apply only in the context of the "right" case. This right bias makes \/ more convenient to use than scala.Either in a monadic context. Methods such as swap, swapped, and leftMap provide functionality that scala.Either exposes through left projections.

A \/ B is also isomorphic to Validation[A, B]. The subtle but important difference is that Applicative instances for Validation accumulates errors ("lefts") while Applicative instances for \/ fail fast on the first "left" they evaluate. This fail-fast behavior allows \/ to have lawful Monad instances that are consistent with their Applicative instances, while Validation cannot.

Source
Either.scala
Linear Supertypes
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. \/
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. AnyRef
  7. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. final class SwitchingDisjunction[X] extends AnyRef

    Permalink

Abstract Value Members

  1. abstract def canEqual(that: Any): Boolean

    Permalink
    Definition Classes
    Equals
  2. abstract def productArity: Int

    Permalink
    Definition Classes
    Product
  3. abstract def productElement(n: Int): Any

    Permalink
    Definition Classes
    Product

Concrete Value Members

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

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

    Permalink
    Definition Classes
    AnyRef → Any
  3. def +++[AA >: A, BB >: B](x: ⇒ \/[AA, BB])(implicit M1: Semigroup[BB], M2: Semigroup[AA]): \/[AA, BB]

    Permalink

    Sums up values inside disjunction, if both are left or right.

    Sums up values inside disjunction, if both are left or right. Returns first left otherwise.

    \/-(v1) +++ \/-(v2) → \/-(v1 + v2)
    \/-(v1) +++ -\/(v2) → -\/(v2)
    -\/(v1) +++ \/-(v2) → -\/(v1)
    -\/(v1) +++ -\/(v2) → -\/(v1 + v2)
  4. def :?>>[X](right: ⇒ X): SwitchingDisjunction[X]

    Permalink

    If this disjunction is right, return the given X value, otherwise, return the X value given to the return value.

  5. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  6. def ===[AA >: A, BB >: B](x: \/[AA, BB])(implicit EA: Equal[AA], EB: Equal[BB]): Boolean

    Permalink

    Compare two disjunction values for equality.

  7. def @\?/[AA, BB](k: (Validation[A, B]) ⇒ Validation[AA, BB]): \/[AA, BB]

    Permalink

    Run a validation function and back to disjunction again.

    Run a validation function and back to disjunction again. Alias for validationed

  8. def ap[AA >: A, C](f: ⇒ \/[AA, (B) ⇒ C]): \/[AA, C]

    Permalink

    Apply a function in the environment of the right of this disjunction.

  9. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  10. def bimap[C, D](f: (A) ⇒ C, g: (B) ⇒ D): \/[C, D]

    Permalink

    Binary functor map on this disjunction.

  11. def bitraverse[F[_], C, D](f: (A) ⇒ F[C], g: (B) ⇒ F[D])(implicit arg0: Functor[F]): F[\/[C, D]]

    Permalink

    Binary functor traverse on this disjunction.

  12. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  13. def compare[AA >: A, BB >: B](x: \/[AA, BB])(implicit EA: Order[AA], EB: Order[BB]): Ordering

    Permalink

    Compare two disjunction values for ordering.

  14. def ensure[AA >: A](onLeft: ⇒ AA)(f: (B) ⇒ Boolean): \/[AA, B]

    Permalink

    Ensures that the right value of this disjunction satisfies the given predicate, or returns left with the given value.

  15. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  16. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  17. def exists[BB >: B](p: (BB) ⇒ Boolean): Boolean

    Permalink

    Return true if this disjunction is a right value satisfying the given predicate.

  18. def filter[AA >: A](p: (B) ⇒ Boolean)(implicit M: Monoid[AA]): \/[AA, B]

    Permalink

    Filter on the right of this disjunction.

  19. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  20. def flatMap[AA >: A, D](g: (B) ⇒ \/[AA, D]): \/[AA, D]

    Permalink

    Bind through the right of this disjunction.

  21. def fold[X](l: (A) ⇒ X, r: (B) ⇒ X): X

    Permalink

    Catamorphism.

    Catamorphism. Run the first given function if left, otherwise, the second given function.

  22. def foldRight[Z](z: ⇒ Z)(f: (B, ⇒ Z) ⇒ Z): Z

    Permalink

    Fold on the right of this disjunction.

  23. def forall[BB >: B](p: (BB) ⇒ Boolean): Boolean

    Permalink

    Return true if this disjunction is a left value or the right value satisfies the given predicate.

  24. def foreach(g: (B) ⇒ Unit): Unit

    Permalink

    Run the side-effect on the right of this disjunction.

  25. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  26. def getOrElse[BB >: B](x: ⇒ BB): BB

    Permalink

    Return the right value of this disjunction or the given default if left.

    Return the right value of this disjunction or the given default if left. Alias for |

  27. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  28. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  29. def isLeft: Boolean

    Permalink

    Return true if this disjunction is left.

  30. def isRight: Boolean

    Permalink

    Return true if this disjunction is right.

  31. def leftMap[C](f: (A) ⇒ C): \/[C, B]

    Permalink

    Run the given function on the left value.

  32. def loopl[AA >: A, BB >: B, X](left: (AA) ⇒ \/[X, \/[AA, BB]], right: (BB) ⇒ X): X

    Permalink

    Spin in tail-position on the left value of this disjunction.

  33. def loopr[AA >: A, BB >: B, X](left: (AA) ⇒ X, right: (BB) ⇒ \/[X, \/[AA, BB]]): X

    Permalink

    Spin in tail-position on the right value of this disjunction.

  34. def map[D](g: (B) ⇒ D): \/[A, D]

    Permalink

    Map on the right of this disjunction.

  35. def merge[AA >: A](implicit ev: <~<[B, AA]): AA

    Permalink

    Return the value from whichever side of the disjunction is defined, given a commonly assignable type.

  36. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  37. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  38. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  39. def orElse[C, BB >: B](x: ⇒ \/[C, BB]): \/[C, BB]

    Permalink

    Return this if it is a right, otherwise, return the given value.

    Return this if it is a right, otherwise, return the given value. Alias for |||

  40. def productIterator: Iterator[Any]

    Permalink
    Definition Classes
    Product
  41. def productPrefix: String

    Permalink
    Definition Classes
    Product
  42. def recover[BB >: B](pf: PartialFunction[A, BB]): \/[A, BB]

    Permalink

    Run the given function on the left and return right with the result.

  43. def recoverWith[AA >: A, BB >: B](pf: PartialFunction[AA, \/[AA, BB]]): \/[AA, BB]

    Permalink

    Run the given function on the left and return the result.

  44. def show[AA >: A, BB >: B](implicit SA: Show[AA], SB: Show[BB]): Cord

    Permalink

    Show for a disjunction value.

  45. def swap: \/[B, A]

    Permalink

    Flip the left/right values in this disjunction.

    Flip the left/right values in this disjunction. Alias for unary_~

  46. def swapped[AA, BB](k: (\/[B, A]) ⇒ \/[BB, AA]): \/[AA, BB]

    Permalink

    Run the given function on this swapped value.

    Run the given function on this swapped value. Alias for ~

  47. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  48. def toEither: Either[A, B]

    Permalink

    Convert to a core scala.Either at your own peril.

  49. def toList: List[B]

    Permalink

    Return an empty list or list with one element on the right of this disjunction.

  50. def toMaybe[BB >: B]: Maybe[BB]

    Permalink

    Return an empty maybe or option with one element on the right of this disjunction.

    Return an empty maybe or option with one element on the right of this disjunction. Useful to sweep errors under the carpet.

  51. def toOption: Option[B]

    Permalink

    Return an empty option or option with one element on the right of this disjunction.

    Return an empty option or option with one element on the right of this disjunction. Useful to sweep errors under the carpet.

  52. def toStream: Stream[B]

    Permalink

    Return an empty stream or stream with one element on the right of this disjunction.

  53. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  54. def toThese: \&/[A, B]

    Permalink

    Convert to a These.

  55. def traverse[F[_], AA >: A, D](g: (B) ⇒ F[D])(implicit arg0: Applicative[F]): F[\/[AA, D]]

    Permalink

    Traverse on the right of this disjunction.

  56. def unary_~: \/[B, A]

    Permalink

    Flip the left/right values in this disjunction.

    Flip the left/right values in this disjunction. Alias for swap

  57. def validation: Validation[A, B]

    Permalink

    Convert to a Validation.

  58. def validationNel[AA >: A]: ValidationNel[AA, B]

    Permalink

    Convert to a ValidationNel.

  59. def validationed[AA, BB](k: (Validation[A, B]) ⇒ Validation[AA, BB]): \/[AA, BB]

    Permalink

    Run a validation function and back to disjunction again.

    Run a validation function and back to disjunction again. Alias for @\?/

  60. def valueOr[BB >: B](x: (A) ⇒ BB): BB

    Permalink

    Return the right value of this disjunction or run the given function on the left.

  61. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  62. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  63. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  64. def |[BB >: B](x: ⇒ BB): BB

    Permalink

    Return the right value of this disjunction or the given default if left.

    Return the right value of this disjunction or the given default if left. Alias for getOrElse

  65. def |||[C, BB >: B](x: ⇒ \/[C, BB]): \/[C, BB]

    Permalink

    Return this if it is a right, otherwise, return the given value.

    Return this if it is a right, otherwise, return the given value. Alias for orElse

  66. def ~[AA, BB](k: (\/[B, A]) ⇒ \/[BB, AA]): \/[AA, BB]

    Permalink

    Run the given function on this swapped value.

    Run the given function on this swapped value. Alias for swapped

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from AnyRef

Inherited from Any

Ungrouped