Represents either:
Success(a)
, orFailure(e)
.
Isomorphic to scala.Either
and scalaz.\/
. The motivation for a Validation
is to provide the instance
Applicative[[a]Validation[E, a]]
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"))
- Type Params
- A
The type of the
Success
- E
The type of the
Failure
- Companion
- object
Type members
Classlikes
Value members
Concrete methods
Sums up values inside validation, if both are success or failure. Returns first failure otherwise.
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)
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
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
Run a disjunction function and back to validation again. Alias for disjunctioned
Run a disjunction function and back to validation again. Alias for disjunctioned
Apply a function in the environment of the success of this validation, accumulating errors.
Apply a function in the environment of the success of this validation, accumulating errors.
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 +|+
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 +|+
Run a disjunction function and back to validation again. Alias for @\/
Run a disjunction function and back to validation again. Alias for @\/
Ensures that the success value of this validation satisfies the given predicate, or fails with the given value.
Ensures that the success value of this validation satisfies the given predicate, or fails with the given value.
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
Return true
if this validation is a success value satisfying the given predicate.
Return true
if this validation is a success value satisfying the given predicate.
If this
is a success, return it; otherwise, if that
is a success, return it; otherwise, combine the failures with the specified semigroup.
If this
is a success, return it; otherwise, if that
is a success, return it; otherwise, combine the failures with the specified semigroup.
Catamorphism. Run the first given function if failure, otherwise, the second given function.
Catamorphism. Run the first given function if failure, otherwise, the second given function.
If this validation is success, return success
, otherwise, return
fail
.
If this validation is success, return success
, otherwise, return
fail
.
Return true
if this validation is a failure value or the success value satisfies the given predicate.
Return true
if this validation is a failure value or the success value satisfies the given predicate.
Run the side-effect on the success of this validation.
Run the side-effect on the success of this validation.
Return the success value of this validation or the given default if failure. Alias for |
Return the success value of this validation or the given default if failure. Alias for |
Spin in tail-position on the failure value of this validation.
Spin in tail-position on the failure value of this validation.
Spin in tail-position on the success value of this validation.
Spin in tail-position on the success value of this validation.
Return this if it is a success, otherwise, return the given value. Alias for |||
Return this if it is a success, otherwise, return the given value. Alias for |||
Flip the failure/success values in this validation. Alias for unary_~
Flip the failure/success values in this validation. Alias for unary_~
Run the given function on this swapped value. Alias for ~
Run the given function on this swapped value. Alias for ~
Return an empty ilist or an ilist with one element on the success of this validation.
Return an empty ilist or an ilist with one element on the success of this validation.
Return an empty list or a list with one element on the success of this validation.
Return an empty list or a list with one 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.
Return an empty maybe or maybe with the element on the success of this validation. Useful to sweep errors under the carpet.
Return an empty option or option with one element on the success of this validation. Useful to sweep errors under the carpet.
Return an empty option or option with one element on the success of this validation. Useful to sweep errors under the carpet.
Return an empty stream or stream with one element on the success of this validation.
Return an empty stream or stream with one element on the success of this validation.
Flip the failure/success values in this validation. Alias for swap
Flip the failure/success values in this validation. Alias for swap
Return the success value of this validation or run the given function on the failure.
Return the success value of this validation or run the given function on the failure.
Return the success value of this validation or the given default if failure. Alias for getOrElse
Return the success value of this validation or the given default if failure. Alias for getOrElse
Return this if it is a success, otherwise, return the given value. Alias for orElse
Return this if it is a success, otherwise, return the given value. Alias for orElse