sealed abstract class Validation[+E, +A] extends Product with Serializable
Represents either:
Success(a)
, orFailure(e)
.
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
- Alphabetic
- By Inheritance
- Validation
- Serializable
- Product
- Equals
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- final class SwitchingValidation[X] extends AnyRef
Abstract Value Members
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- def +++[EE >: E, AA >: A](x: => Validation[EE, AA])(implicit M1: Semigroup[AA], M2: Semigroup[EE]): Validation[EE, AA]
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)
- def +|+[EE >: E, AA >: A](x: Validation[EE, AA])(implicit es: Semigroup[EE], as: Semigroup[AA]): Validation[EE, AA]
If
this
andthat
are both success, or both a failure, combine them with the providedSemigroup
for each.If
this
andthat
are both success, or both a failure, combine them with the providedSemigroup
for each. Otherwise, return the success. Alias forappend
- def :?>>[X](success: => X): SwitchingValidation[X]
If this validation is success, return the given X value, otherwise, return the X value given to the return value.
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def ===[EE >: E, AA >: A](x: Validation[EE, AA])(implicit EE: Equal[EE], EA: Equal[AA]): Boolean
Compare two validations values for equality.
- def @\/[EE, AA](k: (\/[E, A]) => \/[EE, AA]): Validation[EE, AA]
Run a disjunction function and back to validation again.
Run a disjunction function and back to validation again. Alias for
disjunctioned
- def andThen[EE >: E, B](f: (A) => Validation[EE, B]): Validation[EE, B]
- def ap[EE >: E, B](x: => Validation[EE, (A) => B])(implicit E: Semigroup[EE]): Validation[EE, B]
Apply a function in the environment of the success of this validation, accumulating errors.
- def append[EE >: E, AA >: A](that: Validation[EE, AA])(implicit es: Semigroup[EE], as: Semigroup[AA]): Validation[EE, AA]
If
this
andthat
are both success, or both a failure, combine them with the providedSemigroup
for each.If
this
andthat
are both success, or both a failure, combine them with the providedSemigroup
for each. Otherwise, return the success. Alias for+|+
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def bimap[C, D](f: (E) => C, g: (A) => D): Validation[C, D]
Binary functor map on this validation.
- def bitraverse[G[_], C, D](f: (E) => G[C], g: (A) => G[D])(implicit arg0: Functor[G]): G[Validation[C, D]]
Binary functor traverse on this validation.
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- def compare[EE >: E, AA >: A](x: Validation[EE, AA])(implicit EE: Order[EE], EA: Order[AA]): Ordering
Compare two validations values for ordering.
- def disjunction: \/[E, A]
Convert to a disjunction.
- def disjunctioned[EE, AA](k: (\/[E, A]) => \/[EE, AA]): Validation[EE, AA]
Run a disjunction function and back to validation again.
Run a disjunction function and back to validation again. Alias for
@\/
- def ensure[EE >: E](onFailure: => EE)(f: (A) => Boolean): Validation[EE, A]
Ensures that the success value of this validation satisfies the given predicate, or fails with the given value.
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def excepting[EE >: E](pf: PartialFunction[A, EE]): Validation[EE, A]
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
- def exists(f: (A) => Boolean): Boolean
Return
true
if this validation is a success value satisfying the given predicate. - def filter[EE >: E](p: (A) => Boolean)(implicit M: Monoid[EE]): Validation[EE, A]
Filter on the success of this validation.
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- def findSuccess[EE >: E, AA >: A](that: => Validation[EE, AA])(implicit es: Semigroup[EE]): Validation[EE, AA]
If
this
is a success, return it; otherwise, ifthat
is a success, return it; otherwise, combine the failures with the specified semigroup. - def fold[X](fail: (E) => X, succ: (A) => X): X
Catamorphism.
Catamorphism. Run the first given function if failure, otherwise, the second given function.
- def foldRight[B](z: => B)(f: (A, => B) => B): B
Fold on the success of this validation.
- def forall(f: (A) => Boolean): Boolean
Return
true
if this validation is a failure value or the success value satisfies the given predicate. - def foreach[U](f: (A) => U): Unit
Run the side-effect on the success of this validation.
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def getOrElse[AA >: A](x: => AA): AA
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
|
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def isFailure: Boolean
Return
true
if this validation is failure. - final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def isSuccess: Boolean
Return
true
if this validation is success. - def leftMap[C](f: (E) => C): Validation[C, A]
Run the given function on the left value.
- def loopFailure[EE >: E, AA >: A, X](success: (AA) => X, failure: (EE) => \/[X, Validation[EE, AA]]): X
Spin in tail-position on the failure value of this validation.
- def loopSuccess[EE >: E, AA >: A, X](success: (AA) => \/[X, Validation[EE, AA]], failure: (EE) => X): X
Spin in tail-position on the success value of this validation.
- def map[B](f: (A) => B): Validation[E, B]
Map on the success of this validation.
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def orElse[EE >: E, AA >: A](x: => Validation[EE, AA]): Validation[EE, AA]
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
|||
- def productElementName(n: Int): String
- Definition Classes
- Product
- def productElementNames: Iterator[String]
- Definition Classes
- Product
- def productIterator: Iterator[Any]
- Definition Classes
- Product
- def productPrefix: String
- Definition Classes
- Product
- def show[EE >: E, AA >: A](implicit SE: Show[EE], SA: Show[AA]): Cord
Show for a validation value.
- def swap: Validation[A, E]
Flip the failure/success values in this validation.
Flip the failure/success values in this validation. Alias for
unary_~
- def swapped[EE, AA](k: (Validation[A, E]) => Validation[AA, EE]): Validation[EE, AA]
Run the given function on this swapped value.
Run the given function on this swapped value. Alias for
~
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toEither: Either[E, A]
Convert to a core
scala.Either
at your own peril. - def toList: List[A]
Return an empty list or list with one element on the success of this validation.
- def toMaybe[AA >: A]: Maybe[AA]
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.
- def toOption: Option[A]
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.
- def toStream: Stream[A]
Return an empty stream or stream with one element on the success of this validation.
- def toString(): String
- Definition Classes
- AnyRef → Any
- def toValidationNel[EE >: E, AA >: A]: ValidationNel[EE, AA]
Wraps the failure value in a scalaz.NonEmptyList
- def traverse[G[_], EE >: E, B](f: (A) => G[B])(implicit arg0: Applicative[G]): G[Validation[EE, B]]
Traverse on the success of this validation.
- def unary_~: Validation[A, E]
Flip the failure/success values in this validation.
Flip the failure/success values in this validation. Alias for
swap
- def valueOr[AA >: A](x: (E) => AA): AA
Return the success value of this validation or run the given function on the failure.
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- def |[AA >: A](x: => AA): AA
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
- def |||[EE >: E, AA >: A](x: => Validation[EE, AA]): Validation[EE, AA]
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
- def ~[EE, AA](k: (Validation[A, E]) => Validation[AA, EE]): Validation[EE, AA]
Run the given function on this swapped value.
Run the given function on this swapped value. Alias for
swapped