Returns Left containing the errors if this is a Failure or a Right containing the value if this is a Success.
Returns None if this is a Failure or a Some containing the value if this is a Success.
Like map
, but for partial function.
Like map
, but for partial function. If p
us not defined for the value, it return a Failure
val p: PartialFunction[Int, String] = { case 5 => "High five!" } Success(5).collect("OOoops")(p) == Success("High five!") Success(7).collect("OOoops")(p) == Failure(Seq("OOoops")) Failure(Seq("error")).collect("OOoops")(p) == Failure(Seq("error"))
the error to return if the p
is not defined
the partial function to apply if this is a Success
a Success if this was a Success and p
was defined, a Failure otherwise
filter Successful Validation if it does not match the predicate p
filter Successful Validation if it does not match the predicate p
val isFive: Int => Boolean = _ == 5 Success(5).filter("Not five")(isFive) == Success(5) Success(7).filter("Not five")(isFive) == Failure(Seq("Not five")) Failure(Seq("error")).filter("Not five")(isFive) == Failure(Seq("error"))
the error to return if the predicate p
is not verified
the predicate to apply if this is a Success
a Success if this was a Success and the predicate matched, a Failure otherwise
filter Successful Validation if it does not match the predicate p
filter Successful Validation if it does not match the predicate p
the predicate to apply if this is a Success
a Success if this was a Success and the predicate matched, a Failure otherwise
Applies invalid
if this is a Failure or valid
if this is a Success.
Applies invalid
if this is a Failure or valid
if this is a Success.
the function to apply if this is a Failure
the function to apply if this is a Success
the results of applying the function
Applies the given function f
if this is a Success, otherwise returns Unit if this is a Failure
Applies the given function f
if this is a Success, otherwise returns Unit if this is a Failure
the function to apply if this is a Success
Unit
Returns the value from this Success or returns t
if this is a Failure.
[use case] Builds a new Validation by applying a function to the value of this validation if it's a Success
[use case] Builds a new Validation by applying a function to the value of this validation if it's a Success
val f: Int => Int = _ + 2 Success(5).map(f) == Success(7) Failure(Seq("error")).map(f) == Failure(Seq("error"))
the function to apply if this is a Success
the result of applying the function
Returns this Validation if it is a Success or returns t
if it is a Failure.
Applies the given partial function errManager
if this is a Failure, otherwise returns this if this is a Success.
Applies the given function errManager
if this is a Failure, otherwise returns this if this is a Success.
Creates a non-strict filter of this Validation.
Creates a non-strict filter of this Validation.
Note: the difference between c filter p
and c withFilter p
is that
the former creates a new vlaidation, whereas the latter only
restricts the domain of subsequent map
, flatMap
, foreach
,
and withFilter
operations.
the predicate used to test value.
an object of class WithFilter
, which supports
map
, flatMap
, foreach
, and withFilter
operations.
All these operations apply to the value of this Validation
which satisfy the predicate p
.
Validation[E, A] is the result of a validation, where E is the type of each error, and A is the type of the result if the validation is successful The only two possible implementations are Success[E, A](value: A), or Failure[E, A](errors: Seq[E])