Copyright 2008 - 2009 Tony Morris, Runar Bjarnason, Tom Adams, Brad Clow, Ricky Clarkson, Nick Partridge, Jason Zaugg

This software is released under an open source BSD licence.

fj.data
Class Validation<E,T>

java.lang.Object
  extended by fj.data.Validation<E,T>
All Implemented Interfaces:
Iterable<T>

public final class Validation<E,T>
extends Object
implements Iterable<T>

Isomorphic to Either but has renamed functions and represents failure on the left and success on the right. This type also has accumulating functions that accept a Semigroup for binding computation while keeping error values


Nested Class Summary
 class Validation.FailProjection<E,T>
          A failing projection of a validation.
 
Method Summary
<A> Validation<E,A>
accumapply(Semigroup<E> s, Validation<E,F<T,A>> v)
          Function application on the successful side of this validation, or accumulating the errors on the failing side using the given semigroup should one or more be encountered.
<A> Option<E>
accumulate(Semigroup<E> s, Validation<E,A> va)
          Accumulates errors anonymously.
<A,B> Validation<E,B>
accumulate(Semigroup<E> s, Validation<E,A> va, F<T,F<A,B>> f)
          Accumulates errors on the failing side of this or any given validation if one or more are encountered, or applies the given function if all succeeded and returns that value on the successful side.
<A,B> Validation<E,B>
accumulate(Semigroup<E> s, Validation<E,A> va, F2<T,A,B> f)
          Accumulates errors on the failing side of this or any given validation if one or more are encountered, or applies the given function if all succeeded and returns that value on the successful side.
<A,B> Option<E>
accumulate(Semigroup<E> s, Validation<E,A> va, Validation<E,B> vb)
          Accumulates errors anonymously.
<A,B,C> Validation<E,C>
accumulate(Semigroup<E> s, Validation<E,A> va, Validation<E,B> vb, F<T,F<A,F<B,C>>> f)
          Accumulates errors on the failing side of this or any given validation if one or more are encountered, or applies the given function if all succeeded and returns that value on the successful side.
<A,B,C> Validation<E,C>
accumulate(Semigroup<E> s, Validation<E,A> va, Validation<E,B> vb, F3<T,A,B,C> f)
          Accumulates errors on the failing side of this or any given validation if one or more are encountered, or applies the given function if all succeeded and returns that value on the successful side.
<A,B,C> Option<E>
accumulate(Semigroup<E> s, Validation<E,A> va, Validation<E,B> vb, Validation<E,C> vc)
          Accumulates errors anonymously.
<A,B,C,D> Validation<E,D>
accumulate(Semigroup<E> s, Validation<E,A> va, Validation<E,B> vb, Validation<E,C> vc, F<T,F<A,F<B,F<C,D>>>> f)
          Accumulates errors on the failing side of this or any given validation if one or more are encountered, or applies the given function if all succeeded and returns that value on the successful side.
<A,B,C,D> Validation<E,D>
accumulate(Semigroup<E> s, Validation<E,A> va, Validation<E,B> vb, Validation<E,C> vc, F4<T,A,B,C,D> f)
          Accumulates errors on the failing side of this or any given validation if one or more are encountered, or applies the given function if all succeeded and returns that value on the successful side.
<A,B,C,D> Option<E>
accumulate(Semigroup<E> s, Validation<E,A> va, Validation<E,B> vb, Validation<E,C> vc, Validation<E,D> vd)
          Accumulates errors anonymously.
<A,B,C,D,E$>
Validation<E,E$>
accumulate(Semigroup<E> s, Validation<E,A> va, Validation<E,B> vb, Validation<E,C> vc, Validation<E,D> vd, F<T,F<A,F<B,F<C,F<D,E$>>>>> f)
          Accumulates errors on the failing side of this or any given validation if one or more are encountered, or applies the given function if all succeeded and returns that value on the successful side.
<A,B,C,D,E$>
Validation<E,E$>
accumulate(Semigroup<E> s, Validation<E,A> va, Validation<E,B> vb, Validation<E,C> vc, Validation<E,D> vd, F5<T,A,B,C,D,E$> f)
          Accumulates errors on the failing side of this or any given validation if one or more are encountered, or applies the given function if all succeeded and returns that value on the successful side.
<A,B,C,D,E$>
Option<E>
accumulate(Semigroup<E> s, Validation<E,A> va, Validation<E,B> vb, Validation<E,C> vc, Validation<E,D> vd, Validation<E,E$> ve)
          Accumulates errors anonymously.
<A,B,C,D,E$,F$>
Validation<E,F$>
accumulate(Semigroup<E> s, Validation<E,A> va, Validation<E,B> vb, Validation<E,C> vc, Validation<E,D> vd, Validation<E,E$> ve, F<T,F<A,F<B,F<C,F<D,F<E$,F$>>>>>> f)
          Accumulates errors on the failing side of this or any given validation if one or more are encountered, or applies the given function if all succeeded and returns that value on the successful side.
<A,B,C,D,E$,F$>
Validation<E,F$>
accumulate(Semigroup<E> s, Validation<E,A> va, Validation<E,B> vb, Validation<E,C> vc, Validation<E,D> vd, Validation<E,E$> ve, F6<T,A,B,C,D,E$,F$> f)
          Accumulates errors on the failing side of this or any given validation if one or more are encountered, or applies the given function if all succeeded and returns that value on the successful side.
<A,B,C,D,E$,F$>
Option<E>
accumulate(Semigroup<E> s, Validation<E,A> va, Validation<E,B> vb, Validation<E,C> vc, Validation<E,D> vd, Validation<E,E$> ve, Validation<E,F$> vf)
          Accumulates errors anonymously.
<A,B,C,D,E$,F$,G>
Validation<E,G>
accumulate(Semigroup<E> s, Validation<E,A> va, Validation<E,B> vb, Validation<E,C> vc, Validation<E,D> vd, Validation<E,E$> ve, Validation<E,F$> vf, F<T,F<A,F<B,F<C,F<D,F<E$,F<F$,G>>>>>>> f)
          Accumulates errors on the failing side of this or any given validation if one or more are encountered, or applies the given function if all succeeded and returns that value on the successful side.
<A,B,C,D,E$,F$,G>
Validation<E,G>
accumulate(Semigroup<E> s, Validation<E,A> va, Validation<E,B> vb, Validation<E,C> vc, Validation<E,D> vd, Validation<E,E$> ve, Validation<E,F$> vf, F7<T,A,B,C,D,E$,F$,G> f)
          Accumulates errors on the failing side of this or any given validation if one or more are encountered, or applies the given function if all succeeded and returns that value on the successful side.
<A,B,C,D,E$,F$,G>
Option<E>
accumulate(Semigroup<E> s, Validation<E,A> va, Validation<E,B> vb, Validation<E,C> vc, Validation<E,D> vd, Validation<E,E$> ve, Validation<E,F$> vf, Validation<E,G> vg)
          Accumulates errors anonymously.
<A,B,C,D,E$,F$,G,H>
Validation<E,H>
accumulate(Semigroup<E> s, Validation<E,A> va, Validation<E,B> vb, Validation<E,C> vc, Validation<E,D> vd, Validation<E,E$> ve, Validation<E,F$> vf, Validation<E,G> vg, F<T,F<A,F<B,F<C,F<D,F<E$,F<F$,F<G,H>>>>>>>> f)
          Accumulates errors on the failing side of this or any given validation if one or more are encountered, or applies the given function if all succeeded and returns that value on the successful side.
<A,B,C,D,E$,F$,G,H>
Validation<E,H>
accumulate(Semigroup<E> s, Validation<E,A> va, Validation<E,B> vb, Validation<E,C> vc, Validation<E,D> vd, Validation<E,E$> ve, Validation<E,F$> vf, Validation<E,G> vg, F8<T,A,B,C,D,E$,F$,G,H> f)
          Accumulates errors on the failing side of this or any given validation if one or more are encountered, or applies the given function if all succeeded and returns that value on the successful side.
<A> Validation<E,A>
apply(Validation<E,F<T,A>> v)
          Function application on the success value.
<A> Validation<E,A>
bind(F<T,Validation<E,A>> f)
          Binds the given function across this validation's success value if it has one.
static
<E,T> Validation<E,T>
condition(boolean c, E e, T t)
          Returns a validation based on a boolean condition.
static
<E,T> F<Validation<E,T>,Either<E,T>>
either()
          Returns a function that constructs an either with a validation.
 boolean exists(F<T,Boolean> f)
          Returns false if this is a failure or returns the result of the application of the given function to the success value.
 Validation.FailProjection<E,T> f()
          Returns a failing projection of this validation.
 E fail()
          Returns the failing value, or throws an error if there is no failing value.
static
<E,T> Validation<E,T>
fail(E e)
          Returns a failing validation containing the given value.
static
<E,T> Validation<NonEmptyList<E>,T>
failNEL(E e)
          Returns a failing validation containing a non-empty list that contains the given value.
<A> Option<Validation<A,T>>
filter(F<T,Boolean> f)
          Returns None if this is a failure or if the given predicate p does not hold for the success value, otherwise, returns a success in Some.
 boolean forall(F<T,Boolean> f)
          Returns true if this is a failure or returns the result of the application of the given function to the success value.
 void foreach(Effect<T> f)
          Executes a side-effect on the success value if there is one.
 Unit foreach(F<T,Unit> f)
          Executes a side-effect on the success value if there is one.
 boolean isFail()
          Returns true if this is a failure, false otherwise.
 boolean isSuccess()
          Returns true if this is a success, false otherwise.
 Iterator<T> iterator()
          Returns an iterator for this validation.
<A> Validation<E,A>
map(F<T,A> f)
          Maps the given function across the success side of this validation.
 Validation<NonEmptyList<E>,T> nel()
          Puts this validation's failing value in a non-empty list if there is one.
 T on(F<E,T> f)
          The success value or the application of the given function to the failing value.
 T orSuccess(P1<T> t)
          Returns the success value or the given value.
 T orSuccess(T t)
          Returns the success value or the given value.
static Validation<NumberFormatException,Byte> parseByte(String s)
          Parses the given string into a byte.
static Validation<NumberFormatException,Double> parseDouble(String s)
          Parses the given string into a double.
static Validation<NumberFormatException,Float> parseFloat(String s)
          Parses the given string into a float.
static Validation<NumberFormatException,Integer> parseInt(String s)
          Parses the given string into a integer.
static Validation<NumberFormatException,Long> parseLong(String s)
          Parses the given string into a long.
static Validation<NumberFormatException,Short> parseShort(String s)
          Parses the given string into a short.
<A> Validation<E,A>
sequence(Validation<E,A> v)
          Anonymous bind through this validation.
 T success()
          Returns the success value, or throws an error if there is no success value.
static
<E,T> Validation<E,T>
success(T t)
          Returns a succeeding validation containing the given value.
 T successE(P1<String> err)
          Returns the success value or fails with the given error message.
 T successE(String err)
          Returns the success value or fails with the given error message.
 Array<T> toArray()
          Returns a single element array if this is a success value, otherwise an empty list.
 Either<E,T> toEither()
          Returns an either projection of this validation.
 List<T> toList()
          Returns a single element list if this is a success value, otherwise an empty list.
 Option<T> toOption()
          Returns the success value in Some if there is one, otherwise None.
 Stream<T> toStream()
          Returns a single element stream if this is a success value, otherwise an empty list.
static
<E,T> F<Either<E,T>,Validation<E,T>>
validation()
          Returns a function that constructs a validation with an either.
static
<E,T> Validation<E,T>
validation(Either<E,T> e)
          Construct a validation using the given either value.
<X> X
validation(F<E,X> fail, F<T,X> success)
          The catamorphism for validation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isFail

public boolean isFail()
Returns true if this is a failure, false otherwise.

Returns:
true if this is a failure, false otherwise.

isSuccess

public boolean isSuccess()
Returns true if this is a success, false otherwise.

Returns:
true if this is a success, false otherwise.

fail

public E fail()
Returns the failing value, or throws an error if there is no failing value.

Returns:
the failing value, or throws an error if there is no failing value.

success

public T success()
Returns the success value, or throws an error if there is no success value.

Returns:
the success value, or throws an error if there is no success value.

validation

public <X> X validation(F<E,X> fail,
                        F<T,X> success)
The catamorphism for validation. Folds over this validation breaking into left or right.

Parameters:
fail - The function to call if this failed.
success - The function to call if this succeeded.
Returns:
The reduced value.

f

public Validation.FailProjection<E,T> f()
Returns a failing projection of this validation.

Returns:
a failing projection of this validation.

toEither

public Either<E,T> toEither()
Returns an either projection of this validation.

Returns:
An either projection of this validation.

successE

public T successE(P1<String> err)
Returns the success value or fails with the given error message.

Parameters:
err - The error message to fail with.
Returns:
The success value.

successE

public T successE(String err)
Returns the success value or fails with the given error message.

Parameters:
err - The error message to fail with.
Returns:
The success value.

orSuccess

public T orSuccess(P1<T> t)
Returns the success value or the given value.

Parameters:
t - The value to return if this is failure.
Returns:
The success value or the given value.

orSuccess

public T orSuccess(T t)
Returns the success value or the given value.

Parameters:
t - The value to return if this is failure.
Returns:
The success value or the given value.

on

public T on(F<E,T> f)
The success value or the application of the given function to the failing value.

Parameters:
f - The function to execute on the failing value.
Returns:
The success value or the application of the given function to the failing value.

foreach

public Unit foreach(F<T,Unit> f)
Executes a side-effect on the success value if there is one.

Parameters:
f - The side-effect to execute.
Returns:
The unit value.

foreach

public void foreach(Effect<T> f)
Executes a side-effect on the success value if there is one.

Parameters:
f - The side-effect to execute.

map

public <A> Validation<E,A> map(F<T,A> f)
Maps the given function across the success side of this validation.

Parameters:
f - The function to map.
Returns:
A new validation with the function mapped.

bind

public <A> Validation<E,A> bind(F<T,Validation<E,A>> f)
Binds the given function across this validation's success value if it has one.

Parameters:
f - The function to bind across this validation.
Returns:
A new validation value after binding.

sequence

public <A> Validation<E,A> sequence(Validation<E,A> v)
Anonymous bind through this validation.

Parameters:
v - The value to bind with.
Returns:
A validation after binding.

filter

public <A> Option<Validation<A,T>> filter(F<T,Boolean> f)
Returns None if this is a failure or if the given predicate p does not hold for the success value, otherwise, returns a success in Some.

Parameters:
f - The predicate function to test on this success value.
Returns:
None if this is a failure or if the given predicate p does not hold for the success value, otherwise, returns a success in Some.

apply

public <A> Validation<E,A> apply(Validation<E,F<T,A>> v)
Function application on the success value.

Parameters:
v - The validation of the function to apply on the success value.
Returns:
The result of function application in validation.

forall

public boolean forall(F<T,Boolean> f)
Returns true if this is a failure or returns the result of the application of the given function to the success value.

Parameters:
f - The predicate function to test on this success value.
Returns:
true if this is a failure or returns the result of the application of the given function to the success value.

exists

public boolean exists(F<T,Boolean> f)
Returns false if this is a failure or returns the result of the application of the given function to the success value.

Parameters:
f - The predicate function to test on this success value.
Returns:
false if this is a failure or returns the result of the application of the given function to the success value.

toList

public List<T> toList()
Returns a single element list if this is a success value, otherwise an empty list.

Returns:
A single element list if this is a success value, otherwise an empty list.

toOption

public Option<T> toOption()
Returns the success value in Some if there is one, otherwise None.

Returns:
The success value in Some if there is one, otherwise None.

toArray

public Array<T> toArray()
Returns a single element array if this is a success value, otherwise an empty list.

Returns:
A single element array if this is a success value, otherwise an empty list.

toStream

public Stream<T> toStream()
Returns a single element stream if this is a success value, otherwise an empty list.

Returns:
A single element stream if this is a success value, otherwise an empty list.

accumapply

public <A> Validation<E,A> accumapply(Semigroup<E> s,
                                      Validation<E,F<T,A>> v)
Function application on the successful side of this validation, or accumulating the errors on the failing side using the given semigroup should one or more be encountered.

Parameters:
s - The semigroup to accumulate errors with if
v - The validating function to apply.
Returns:
A failing validation if this or the given validation failed (with errors accumulated if both) or a succeeding validation if both succeeded.

accumulate

public <A,B> Validation<E,B> accumulate(Semigroup<E> s,
                                        Validation<E,A> va,
                                        F<T,F<A,B>> f)
Accumulates errors on the failing side of this or any given validation if one or more are encountered, or applies the given function if all succeeded and returns that value on the successful side.

Parameters:
s - The semigroup to accumulate errors with if one or more validations fail.
va - The second validation to accumulate errors with if it failed.
f - The function to apply if all validations have succeeded.
Returns:
A succeeding validation if all validations succeeded, or a failing validation with errors accumulated if one or more failed.

accumulate

public <A,B> Validation<E,B> accumulate(Semigroup<E> s,
                                        Validation<E,A> va,
                                        F2<T,A,B> f)
Accumulates errors on the failing side of this or any given validation if one or more are encountered, or applies the given function if all succeeded and returns that value on the successful side.

Parameters:
s - The semigroup to accumulate errors with if one or more validations fail.
va - The second validation to accumulate errors with if it failed.
f - The function to apply if all validations have succeeded.
Returns:
A succeeding validation if all validations succeeded, or a failing validation with errors accumulated if one or more failed.

accumulate

public <A> Option<E> accumulate(Semigroup<E> s,
                                Validation<E,A> va)
Accumulates errors anonymously.

Parameters:
s - The semigroup to accumulate errors with if one or more validations fail.
va - The second validation to accumulate errors with if it failed.
Returns:
A Some if one or more validations failed (accumulated with the semigroup), otherwise, None.

accumulate

public <A,B,C> Validation<E,C> accumulate(Semigroup<E> s,
                                          Validation<E,A> va,
                                          Validation<E,B> vb,
                                          F<T,F<A,F<B,C>>> f)
Accumulates errors on the failing side of this or any given validation if one or more are encountered, or applies the given function if all succeeded and returns that value on the successful side.

Parameters:
s - The semigroup to accumulate errors with if one or more validations fail.
va - The second validation to accumulate errors with if it failed.
vb - The third validation to accumulate errors with if it failed.
f - The function to apply if all validations have succeeded.
Returns:
A succeeding validation if all validations succeeded, or a failing validation with errors accumulated if one or more failed.

accumulate

public <A,B,C> Validation<E,C> accumulate(Semigroup<E> s,
                                          Validation<E,A> va,
                                          Validation<E,B> vb,
                                          F3<T,A,B,C> f)
Accumulates errors on the failing side of this or any given validation if one or more are encountered, or applies the given function if all succeeded and returns that value on the successful side.

Parameters:
s - The semigroup to accumulate errors with if one or more validations fail.
va - The second validation to accumulate errors with if it failed.
vb - The third validation to accumulate errors with if it failed.
f - The function to apply if all validations have succeeded.
Returns:
A succeeding validation if all validations succeeded, or a failing validation with errors accumulated if one or more failed.

accumulate

public <A,B> Option<E> accumulate(Semigroup<E> s,
                                  Validation<E,A> va,
                                  Validation<E,B> vb)
Accumulates errors anonymously.

Parameters:
s - The semigroup to accumulate errors with if one or more validations fail.
va - The second validation to accumulate errors with if it failed.
vb - The third validation to accumulate errors with if it failed.
Returns:
A Some if one or more validations failed (accumulated with the semigroup), otherwise, None.

accumulate

public <A,B,C,D> Validation<E,D> accumulate(Semigroup<E> s,
                                            Validation<E,A> va,
                                            Validation<E,B> vb,
                                            Validation<E,C> vc,
                                            F<T,F<A,F<B,F<C,D>>>> f)
Accumulates errors on the failing side of this or any given validation if one or more are encountered, or applies the given function if all succeeded and returns that value on the successful side.

Parameters:
s - The semigroup to accumulate errors with if one or more validations fail.
va - The second validation to accumulate errors with if it failed.
vb - The third validation to accumulate errors with if it failed.
vc - The fourth validation to accumulate errors with if it failed.
f - The function to apply if all validations have succeeded.
Returns:
A succeeding validation if all validations succeeded, or a failing validation with errors accumulated if one or more failed.

accumulate

public <A,B,C,D> Validation<E,D> accumulate(Semigroup<E> s,
                                            Validation<E,A> va,
                                            Validation<E,B> vb,
                                            Validation<E,C> vc,
                                            F4<T,A,B,C,D> f)
Accumulates errors on the failing side of this or any given validation if one or more are encountered, or applies the given function if all succeeded and returns that value on the successful side.

Parameters:
s - The semigroup to accumulate errors with if one or more validations fail.
va - The second validation to accumulate errors with if it failed.
vb - The third validation to accumulate errors with if it failed.
vc - The fourth validation to accumulate errors with if it failed.
f - The function to apply if all validations have succeeded.
Returns:
A succeeding validation if all validations succeeded, or a failing validation with errors accumulated if one or more failed.

accumulate

public <A,B,C> Option<E> accumulate(Semigroup<E> s,
                                    Validation<E,A> va,
                                    Validation<E,B> vb,
                                    Validation<E,C> vc)
Accumulates errors anonymously.

Parameters:
s - The semigroup to accumulate errors with if one or more validations fail.
va - The second validation to accumulate errors with if it failed.
vb - The third validation to accumulate errors with if it failed.
vc - The fourth validation to accumulate errors with if it failed.
Returns:
A Some if one or more validations failed (accumulated with the semigroup), otherwise, None.

accumulate

public <A,B,C,D,E$> Validation<E,E$> accumulate(Semigroup<E> s,
                                                Validation<E,A> va,
                                                Validation<E,B> vb,
                                                Validation<E,C> vc,
                                                Validation<E,D> vd,
                                                F<T,F<A,F<B,F<C,F<D,E$>>>>> f)
Accumulates errors on the failing side of this or any given validation if one or more are encountered, or applies the given function if all succeeded and returns that value on the successful side.

Parameters:
s - The semigroup to accumulate errors with if one or more validations fail.
va - The second validation to accumulate errors with if it failed.
vb - The third validation to accumulate errors with if it failed.
vc - The fourth validation to accumulate errors with if it failed.
vd - The fifth validation to accumulate errors with if it failed.
f - The function to apply if all validations have succeeded.
Returns:
A succeeding validation if all validations succeeded, or a failing validation with errors accumulated if one or more failed.

accumulate

public <A,B,C,D,E$> Validation<E,E$> accumulate(Semigroup<E> s,
                                                Validation<E,A> va,
                                                Validation<E,B> vb,
                                                Validation<E,C> vc,
                                                Validation<E,D> vd,
                                                F5<T,A,B,C,D,E$> f)
Accumulates errors on the failing side of this or any given validation if one or more are encountered, or applies the given function if all succeeded and returns that value on the successful side.

Parameters:
s - The semigroup to accumulate errors with if one or more validations fail.
va - The second validation to accumulate errors with if it failed.
vb - The third validation to accumulate errors with if it failed.
vc - The fourth validation to accumulate errors with if it failed.
vd - The fifth validation to accumulate errors with if it failed.
f - The function to apply if all validations have succeeded.
Returns:
A succeeding validation if all validations succeeded, or a failing validation with errors accumulated if one or more failed.

accumulate

public <A,B,C,D> Option<E> accumulate(Semigroup<E> s,
                                      Validation<E,A> va,
                                      Validation<E,B> vb,
                                      Validation<E,C> vc,
                                      Validation<E,D> vd)
Accumulates errors anonymously.

Parameters:
s - The semigroup to accumulate errors with if one or more validations fail.
va - The second validation to accumulate errors with if it failed.
vb - The third validation to accumulate errors with if it failed.
vc - The fourth validation to accumulate errors with if it failed.
vd - The fifth validation to accumulate errors with if it failed.
Returns:
A Some if one or more validations failed (accumulated with the semigroup), otherwise, None.

accumulate

public <A,B,C,D,E$,F$> Validation<E,F$> accumulate(Semigroup<E> s,
                                                   Validation<E,A> va,
                                                   Validation<E,B> vb,
                                                   Validation<E,C> vc,
                                                   Validation<E,D> vd,
                                                   Validation<E,E$> ve,
                                                   F<T,F<A,F<B,F<C,F<D,F<E$,F$>>>>>> f)
Accumulates errors on the failing side of this or any given validation if one or more are encountered, or applies the given function if all succeeded and returns that value on the successful side.

Parameters:
s - The semigroup to accumulate errors with if one or more validations fail.
va - The second validation to accumulate errors with if it failed.
vb - The third validation to accumulate errors with if it failed.
vc - The fourth validation to accumulate errors with if it failed.
vd - The fifth validation to accumulate errors with if it failed.
ve - The sixth validation to accumulate errors with if it failed.
f - The function to apply if all validations have succeeded.
Returns:
A succeeding validation if all validations succeeded, or a failing validation with errors accumulated if one or more failed.

accumulate

public <A,B,C,D,E$,F$> Validation<E,F$> accumulate(Semigroup<E> s,
                                                   Validation<E,A> va,
                                                   Validation<E,B> vb,
                                                   Validation<E,C> vc,
                                                   Validation<E,D> vd,
                                                   Validation<E,E$> ve,
                                                   F6<T,A,B,C,D,E$,F$> f)
Accumulates errors on the failing side of this or any given validation if one or more are encountered, or applies the given function if all succeeded and returns that value on the successful side.

Parameters:
s - The semigroup to accumulate errors with if one or more validations fail.
va - The second validation to accumulate errors with if it failed.
vb - The third validation to accumulate errors with if it failed.
vc - The fourth validation to accumulate errors with if it failed.
vd - The fifth validation to accumulate errors with if it failed.
ve - The sixth validation to accumulate errors with if it failed.
f - The function to apply if all validations have succeeded.
Returns:
A succeeding validation if all validations succeeded, or a failing validation with errors accumulated if one or more failed.

accumulate

public <A,B,C,D,E$> Option<E> accumulate(Semigroup<E> s,
                                         Validation<E,A> va,
                                         Validation<E,B> vb,
                                         Validation<E,C> vc,
                                         Validation<E,D> vd,
                                         Validation<E,E$> ve)
Accumulates errors anonymously.

Parameters:
s - The semigroup to accumulate errors with if one or more validations fail.
va - The second validation to accumulate errors with if it failed.
vb - The third validation to accumulate errors with if it failed.
vc - The fourth validation to accumulate errors with if it failed.
vd - The fifth validation to accumulate errors with if it failed.
ve - The sixth validation to accumulate errors with if it failed.
Returns:
A Some if one or more validations failed (accumulated with the semigroup), otherwise, None.

accumulate

public <A,B,C,D,E$,F$,G> Validation<E,G> accumulate(Semigroup<E> s,
                                                    Validation<E,A> va,
                                                    Validation<E,B> vb,
                                                    Validation<E,C> vc,
                                                    Validation<E,D> vd,
                                                    Validation<E,E$> ve,
                                                    Validation<E,F$> vf,
                                                    F<T,F<A,F<B,F<C,F<D,F<E$,F<F$,G>>>>>>> f)
Accumulates errors on the failing side of this or any given validation if one or more are encountered, or applies the given function if all succeeded and returns that value on the successful side.

Parameters:
s - The semigroup to accumulate errors with if one or more validations fail.
va - The second validation to accumulate errors with if it failed.
vb - The third validation to accumulate errors with if it failed.
vc - The fourth validation to accumulate errors with if it failed.
vd - The fifth validation to accumulate errors with if it failed.
ve - The sixth validation to accumulate errors with if it failed.
vf - The seventh validation to accumulate errors with if it failed.
f - The function to apply if all validations have succeeded.
Returns:
A succeeding validation if all validations succeeded, or a failing validation with errors accumulated if one or more failed.

accumulate

public <A,B,C,D,E$,F$,G> Validation<E,G> accumulate(Semigroup<E> s,
                                                    Validation<E,A> va,
                                                    Validation<E,B> vb,
                                                    Validation<E,C> vc,
                                                    Validation<E,D> vd,
                                                    Validation<E,E$> ve,
                                                    Validation<E,F$> vf,
                                                    F7<T,A,B,C,D,E$,F$,G> f)
Accumulates errors on the failing side of this or any given validation if one or more are encountered, or applies the given function if all succeeded and returns that value on the successful side.

Parameters:
s - The semigroup to accumulate errors with if one or more validations fail.
va - The second validation to accumulate errors with if it failed.
vb - The third validation to accumulate errors with if it failed.
vc - The fourth validation to accumulate errors with if it failed.
vd - The fifth validation to accumulate errors with if it failed.
ve - The sixth validation to accumulate errors with if it failed.
vf - The seventh validation to accumulate errors with if it failed.
f - The function to apply if all validations have succeeded.
Returns:
A succeeding validation if all validations succeeded, or a failing validation with errors accumulated if one or more failed.

accumulate

public <A,B,C,D,E$,F$> Option<E> accumulate(Semigroup<E> s,
                                            Validation<E,A> va,
                                            Validation<E,B> vb,
                                            Validation<E,C> vc,
                                            Validation<E,D> vd,
                                            Validation<E,E$> ve,
                                            Validation<E,F$> vf)
Accumulates errors anonymously.

Parameters:
s - The semigroup to accumulate errors with if one or more validations fail.
va - The second validation to accumulate errors with if it failed.
vb - The third validation to accumulate errors with if it failed.
vc - The fourth validation to accumulate errors with if it failed.
vd - The fifth validation to accumulate errors with if it failed.
ve - The sixth validation to accumulate errors with if it failed.
vf - The seventh validation to accumulate errors with if it failed.
Returns:
A Some if one or more validations failed (accumulated with the semigroup), otherwise, None.

accumulate

public <A,B,C,D,E$,F$,G,H> Validation<E,H> accumulate(Semigroup<E> s,
                                                      Validation<E,A> va,
                                                      Validation<E,B> vb,
                                                      Validation<E,C> vc,
                                                      Validation<E,D> vd,
                                                      Validation<E,E$> ve,
                                                      Validation<E,F$> vf,
                                                      Validation<E,G> vg,
                                                      F<T,F<A,F<B,F<C,F<D,F<E$,F<F$,F<G,H>>>>>>>> f)
Accumulates errors on the failing side of this or any given validation if one or more are encountered, or applies the given function if all succeeded and returns that value on the successful side.

Parameters:
s - The semigroup to accumulate errors with if one or more validations fail.
va - The second validation to accumulate errors with if it failed.
vb - The third validation to accumulate errors with if it failed.
vc - The fourth validation to accumulate errors with if it failed.
vd - The fifth validation to accumulate errors with if it failed.
ve - The sixth validation to accumulate errors with if it failed.
vf - The seventh validation to accumulate errors with if it failed.
vg - The eighth validation to accumulate errors with if it failed.
f - The function to apply if all validations have succeeded.
Returns:
A succeeding validation if all validations succeeded, or a failing validation with errors accumulated if one or more failed.

accumulate

public <A,B,C,D,E$,F$,G,H> Validation<E,H> accumulate(Semigroup<E> s,
                                                      Validation<E,A> va,
                                                      Validation<E,B> vb,
                                                      Validation<E,C> vc,
                                                      Validation<E,D> vd,
                                                      Validation<E,E$> ve,
                                                      Validation<E,F$> vf,
                                                      Validation<E,G> vg,
                                                      F8<T,A,B,C,D,E$,F$,G,H> f)
Accumulates errors on the failing side of this or any given validation if one or more are encountered, or applies the given function if all succeeded and returns that value on the successful side.

Parameters:
s - The semigroup to accumulate errors with if one or more validations fail.
va - The second validation to accumulate errors with if it failed.
vb - The third validation to accumulate errors with if it failed.
vc - The fourth validation to accumulate errors with if it failed.
vd - The fifth validation to accumulate errors with if it failed.
ve - The sixth validation to accumulate errors with if it failed.
vf - The seventh validation to accumulate errors with if it failed.
vg - The eighth validation to accumulate errors with if it failed.
f - The function to apply if all validations have succeeded.
Returns:
A succeeding validation if all validations succeeded, or a failing validation with errors accumulated if one or more failed.

accumulate

public <A,B,C,D,E$,F$,G> Option<E> accumulate(Semigroup<E> s,
                                              Validation<E,A> va,
                                              Validation<E,B> vb,
                                              Validation<E,C> vc,
                                              Validation<E,D> vd,
                                              Validation<E,E$> ve,
                                              Validation<E,F$> vf,
                                              Validation<E,G> vg)
Accumulates errors anonymously.

Parameters:
s - The semigroup to accumulate errors with if one or more validations fail.
va - The second validation to accumulate errors with if it failed.
vb - The third validation to accumulate errors with if it failed.
vc - The fourth validation to accumulate errors with if it failed.
vd - The fifth validation to accumulate errors with if it failed.
ve - The sixth validation to accumulate errors with if it failed.
vf - The seventh validation to accumulate errors with if it failed.
vg - The eighth validation to accumulate errors with if it failed.
Returns:
A Some if one or more validations failed (accumulated with the semigroup), otherwise, None.

iterator

public Iterator<T> iterator()
Returns an iterator for this validation. This method exists to permit the use in a for-each loop.

Specified by:
iterator in interface Iterable<T>
Returns:
A iterator for this validation.

nel

public Validation<NonEmptyList<E>,T> nel()
Puts this validation's failing value in a non-empty list if there is one.

Returns:
A validation with its failing value in a non-empty list if there is one.

validation

public static <E,T> Validation<E,T> validation(Either<E,T> e)
Construct a validation using the given either value.

Parameters:
e - The either value to construct a validation with.
Returns:
A validation using the given either value.

validation

public static <E,T> F<Either<E,T>,Validation<E,T>> validation()
Returns a function that constructs a validation with an either.

Returns:
A function that constructs a validation with an either.

either

public static <E,T> F<Validation<E,T>,Either<E,T>> either()
Returns a function that constructs an either with a validation.

Returns:
A function that constructs an either with a validation.

success

public static <E,T> Validation<E,T> success(T t)
Returns a succeeding validation containing the given value.

Parameters:
t - The value to use in the succeeding validation.
Returns:
A succeeding validation containing the given value.

fail

public static <E,T> Validation<E,T> fail(E e)
Returns a failing validation containing the given value.

Parameters:
e - The value to use in the failing validation.
Returns:
A failing validation containing the given value.

failNEL

public static <E,T> Validation<NonEmptyList<E>,T> failNEL(E e)
Returns a failing validation containing a non-empty list that contains the given value.

Parameters:
e - The value to use in a non-empty list for the failing validation.
Returns:
A failing validation containing a non-empty list that contains the given value.

condition

public static <E,T> Validation<E,T> condition(boolean c,
                                              E e,
                                              T t)
Returns a validation based on a boolean condition. If the condition is true, the validation succeeds, otherwise it fails.

Parameters:
c - The condition to base the returned validation on.
e - The failing value to use if the condition is false.
t - The succeeding value to use if the condition is true.
Returns:
A validation based on a boolean condition.

parseByte

public static Validation<NumberFormatException,Byte> parseByte(String s)
Parses the given string into a byte.

Parameters:
s - The string to parse.
Returns:
A successfully parse byte or a failing exception.

parseDouble

public static Validation<NumberFormatException,Double> parseDouble(String s)
Parses the given string into a double.

Parameters:
s - The string to parse.
Returns:
A successfully parse double or a failing exception.

parseFloat

public static Validation<NumberFormatException,Float> parseFloat(String s)
Parses the given string into a float.

Parameters:
s - The string to parse.
Returns:
A successfully parse float or a failing exception.

parseInt

public static Validation<NumberFormatException,Integer> parseInt(String s)
Parses the given string into a integer.

Parameters:
s - The string to parse.
Returns:
A successfully parse integer or a failing exception.

parseLong

public static Validation<NumberFormatException,Long> parseLong(String s)
Parses the given string into a long.

Parameters:
s - The string to parse.
Returns:
A successfully parse long or a failing exception.

parseShort

public static Validation<NumberFormatException,Short> parseShort(String s)
Parses the given string into a short.

Parameters:
s - The string to parse.
Returns:
A successfully parse short or a failing exception.

Copyright 2008 - 2009 Tony Morris, Runar Bjarnason, Tom Adams, Brad Clow, Ricky Clarkson, Nick Partridge, Jason Zaugg

This software is released under an open source BSD licence.