Class/Object

scalaz

Validation

Related Docs: object Validation | package scalaz

Permalink

sealed abstract class Validation[+E, +A] extends Product with Serializable

Represents either:

Isomorphic to scala.Either and scalaz.\/. The motivation for a Validation is to provide the instance Applicativea that accumulate failures through a scalaz.Semigroup[E].

scalaz.NonEmptyList is commonly chosen as a type constructor for the type E. As a convenience, an alias scalaz.ValidationNel[E] is provided as a shorthand for scalaz.Validation[NonEmptyList[E]], and a method Validation#toValidationNel converts Validation[E] to ValidationNel[E].

Example:

import scalaz._, std.AllInstances._

def parseInt(s: String): Validation[String, Int] =
  try { Success(s.toInt) } catch { case ex: NumberFormatException => Failure(ex.getMessage) }
val V = Applicative[ValidationNel[String, ?]]

val x: ValidationNel[String, Int] =
  V.apply2(parseInt("1.x").toValidationNel, parseInt("1..0").toValidationNel)(_ * _)
  // Failure(NonEmptyList(For input string: "1..0", For input string: "1.x"))
E

The type of the Failure

A

The type of the Success

Source
Validation.scala
Linear Supertypes
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Validation
  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 SwitchingValidation[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 +++[EE >: E, AA >: A](x: ⇒ Validation[EE, AA])(implicit M1: Semigroup[AA], M2: Semigroup[EE]): Validation[EE, AA]

    Permalink

    Sums up values inside validation, if both are success or failure.

    Sums up values inside validation, if both are success or failure. Returns first failure otherwise.

    success(v1) +++ success(v2) → success(v1 + v2)
    success(v1) +++ failure(v2) → failure(v2)
    failure(v1) +++ success(v2) → failure(v1)
    failure(v1) +++ failure(v2) → failure(v1 + v2)
  4. def +|+[EE >: E, AA >: A](x: Validation[EE, AA])(implicit es: Semigroup[EE], as: Semigroup[AA]): Validation[EE, AA]

    Permalink

    If this and that are both success, or both a failure, combine them with the provided Semigroup for each.

    If this and that are both success, or both a failure, combine them with the provided Semigroup for each. Otherwise, return the success. Alias for append

  5. def :?>>[X](success: ⇒ X): SwitchingValidation[X]

    Permalink

    If this validation is success, return the given X value, otherwise, return the X value given to the return value.

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

    Permalink
    Definition Classes
    AnyRef → Any
  7. def ===[EE >: E, AA >: A](x: Validation[EE, AA])(implicit EE: Equal[EE], EA: Equal[AA]): Boolean

    Permalink

    Compare two validations values for equality.

  8. def @\/[EE, AA](k: (\/[E, A]) ⇒ \/[EE, AA]): Validation[EE, AA]

    Permalink

    Run a disjunction function and back to validation again.

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

  9. def ap[EE >: E, B](x: ⇒ Validation[EE, (A) ⇒ B])(implicit E: Semigroup[EE]): Validation[EE, B]

    Permalink

    Apply a function in the environment of the success of this validation, accumulating errors.

  10. def append[EE >: E, AA >: A](that: Validation[EE, AA])(implicit es: Semigroup[EE], as: Semigroup[AA]): Validation[EE, AA]

    Permalink

    If this and that are both success, or both a failure, combine them with the provided Semigroup for each.

    If this and that are both success, or both a failure, combine them with the provided Semigroup for each. Otherwise, return the success. Alias for +|+

  11. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  12. def bimap[C, D](f: (E) ⇒ C, g: (A) ⇒ D): Validation[C, D]

    Permalink

    Binary functor map on this validation.

  13. def bitraverse[G[_], C, D](f: (E) ⇒ G[C], g: (A) ⇒ G[D])(implicit arg0: Functor[G]): G[Validation[C, D]]

    Permalink

    Binary functor traverse on this validation.

  14. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  15. def compare[EE >: E, AA >: A](x: Validation[EE, AA])(implicit EE: Order[EE], EA: Order[AA]): Ordering

    Permalink

    Compare two validations values for ordering.

  16. def disjunction: \/[E, A]

    Permalink

    Convert to a disjunction.

  17. def disjunctioned[EE, AA](k: (\/[E, A]) ⇒ \/[EE, AA]): Validation[EE, AA]

    Permalink

    Run a disjunction function and back to validation again.

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

  18. def ensure[EE >: E](onFailure: ⇒ EE)(f: (A) ⇒ Boolean): Validation[EE, A]

    Permalink

    Ensures that the success value of this validation satisfies the given predicate, or fails with the given value.

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

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

    Permalink
    Definition Classes
    AnyRef → Any
  21. def excepting[EE >: E](pf: PartialFunction[A, EE]): Validation[EE, A]

    Permalink

    Return a Validation formed by the application of a partial function across the success of this value:

    Return a Validation formed by the application of a partial function across the success of this value:

    strings map (_.parseInt excepting { case i if i < 0 => new Exception(s"Int must be positive: $i") })
    Since

    7.0.2

  22. def exists(f: (A) ⇒ Boolean): Boolean

    Permalink

    Return true if this validation is a success value satisfying the given predicate.

  23. def filter[EE >: E](p: (A) ⇒ Boolean)(implicit M: Monoid[EE]): Validation[EE, A]

    Permalink

    Filter on the success of this validation.

  24. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  25. def findSuccess[EE >: E, AA >: A](that: ⇒ Validation[EE, AA])(implicit es: Semigroup[EE]): Validation[EE, AA]

    Permalink

    If this is a success, return it; otherwise, if that is a success, return it; otherwise, combine the failures with the specified semigroup.

  26. def fold[X](fail: (E) ⇒ X, succ: (A) ⇒ X): X

    Permalink

    Catamorphism.

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

  27. def foldRight[B](z: ⇒ B)(f: (A, ⇒ B) ⇒ B): B

    Permalink

    Fold on the success of this validation.

  28. def forall(f: (A) ⇒ Boolean): Boolean

    Permalink

    Return true if this validation is a failure value or the success value satisfies the given predicate.

  29. def foreach[U](f: (A) ⇒ U): Unit

    Permalink

    Run the side-effect on the success of this validation.

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

    Permalink
    Definition Classes
    AnyRef → Any
  31. def getOrElse[AA >: A](x: ⇒ AA): AA

    Permalink

    Return the success value of this validation or the given default if failure.

    Return the success value of this validation or the given default if failure. Alias for |

  32. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  33. def isFailure: Boolean

    Permalink

    Return true if this validation is failure.

  34. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  35. def isSuccess: Boolean

    Permalink

    Return true if this validation is success.

  36. def leftMap[C](f: (E) ⇒ C): Validation[C, A]

    Permalink

    Run the given function on the left value.

  37. def loopFailure[EE >: E, AA >: A, X](success: (AA) ⇒ X, failure: (EE) ⇒ \/[X, Validation[EE, AA]]): X

    Permalink

    Spin in tail-position on the failure value of this validation.

  38. def loopSuccess[EE >: E, AA >: A, X](success: (AA) ⇒ \/[X, Validation[EE, AA]], failure: (EE) ⇒ X): X

    Permalink

    Spin in tail-position on the success value of this validation.

  39. def map[B](f: (A) ⇒ B): Validation[E, B]

    Permalink

    Map on the success of this validation.

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

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

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

    Permalink
    Definition Classes
    AnyRef
  43. def orElse[EE >: E, AA >: A](x: ⇒ Validation[EE, AA]): Validation[EE, AA]

    Permalink

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

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

  44. def productIterator: Iterator[Any]

    Permalink
    Definition Classes
    Product
  45. def productPrefix: String

    Permalink
    Definition Classes
    Product
  46. def show[EE >: E, AA >: A](implicit SE: Show[EE], SA: Show[AA]): Cord

    Permalink

    Show for a validation value.

  47. def swap: Validation[A, E]

    Permalink

    Flip the failure/success values in this validation.

    Flip the failure/success values in this validation. Alias for unary_~

  48. def swapped[EE, AA](k: (Validation[A, E]) ⇒ Validation[AA, EE]): Validation[EE, AA]

    Permalink

    Run the given function on this swapped value.

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

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

    Permalink
    Definition Classes
    AnyRef
  50. def toEither: Either[E, A]

    Permalink

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

  51. def toList: List[A]

    Permalink

    Return an empty list or list with one element on the success of this validation.

  52. def toMaybe[AA >: A]: Maybe[AA]

    Permalink

    Return an empty maybe or maybe with the element on the success of this validation.

    Return an empty maybe or maybe with the element on the success of this validation. Useful to sweep errors under the carpet.

  53. def toOption: Option[A]

    Permalink

    Return an empty option or option with one element on the success of this validation.

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

  54. def toStream: Stream[A]

    Permalink

    Return an empty stream or stream with one element on the success of this validation.

  55. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  56. def toValidationNel[EE >: E, AA >: A]: ValidationNel[EE, AA]

    Permalink

    Wraps the failure value in a scalaz.NonEmptyList

  57. def traverse[G[_], EE >: E, B](f: (A) ⇒ G[B])(implicit arg0: Applicative[G]): G[Validation[EE, B]]

    Permalink

    Traverse on the success of this validation.

  58. def unary_~: Validation[A, E]

    Permalink

    Flip the failure/success values in this validation.

    Flip the failure/success values in this validation. Alias for swap

  59. def valueOr[AA >: A](x: (E) ⇒ AA): AA

    Permalink

    Return the success value of this validation or run the given function on the failure.

  60. final def wait(): Unit

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

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

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  63. def |[AA >: A](x: ⇒ AA): AA

    Permalink

    Return the success value of this validation or the given default if failure.

    Return the success value of this validation or the given default if failure. Alias for getOrElse

  64. def |||[EE >: E, AA >: A](x: ⇒ Validation[EE, AA]): Validation[EE, AA]

    Permalink

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

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

  65. def ~[EE, AA](k: (Validation[A, E]) ⇒ Validation[AA, EE]): Validation[EE, AA]

    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