कोई वास्तविक दुनिया उदाहरणों के साथ समझा सकता है scalaz.Validation
के तरीकों के नीचे कैसे काम करता है? मेरा मतलब है loopSuccess
और loopFailure
। स्रोत कोड (scalaz7) सेकार्य scalaz कैसे काम करता है। प्रमाणीकरण loopSuccess और loopFailure
Snippetes:
scalaz.Validation:
/** Spin in tail-position on the success value of this validation. */
def loopSuccess[EE >: E, AA >: A, X](success: AA => X \/ Validation[EE, AA], failure: EE => X): X =
Validation.loopSuccess(this, success, failure)
/** Spin in tail-position on the failure value of this validation. */
def loopFailure[EE >: E, AA >: A, X](success: AA => X, failure: EE => X \/ Validation[EE, AA]): X =
Validation.loopFailure(this, success, failure)
साथी वस्तु:
object Validation extends ValidationFunctions with ValidationInstances {
/** Spin in tail-position on the success value of the given validation. */
@annotation.tailrec
final def loopSuccess[E, A, X](d: Validation[E, A], success: A => X \/ Validation[E, A], failure: E => X): X =
d match {
case Failure(e) => failure(e)
case Success(a) => success(a) match {
case -\/(x) => x
case \/-(q) => loopSuccess(q, success, failure)
}
}
/** Spin in tail-position on the failure value of the given validation. */
@annotation.tailrec
final def loopFailure[E, A, X](d: Validation[E, A], success: A => X, failure: E => X \/ Validation[E, A]): X =
d match {
case Failure(e) => failure(e) match {
case -\/(x) => x
case \/-(q) => loopFailure(q, success, failure)
}
case Success(a) => success(a)
}
}