Skip to content

Instantly share code, notes, and snippets.

@arkadius
Last active August 29, 2015 14:04
Show Gist options
  • Save arkadius/daa9151dd5df5008ebc2 to your computer and use it in GitHub Desktop.
Save arkadius/daa9151dd5df5008ebc2 to your computer and use it in GitHub Desktop.
trait ValidatingPhasesChain[-In, +OutF, +OutS] extends PhasesChain[In, Validation[OutF, OutS]] {
def ::[NIn, NOutF >: OutF](prev: ValidatingPhase[NIn, NOutF, In]): ValidatingPhasesChain[NIn, NOutF, OutS] =
new ChainedValidatingPhase(prev, this)
protected def processIfSuccessOrMoveProgress[MidF, MidS, OutSS](progress: MultiPhasedProgress)
(next: ValidatingPhasesChain[MidS, MidF, OutSS])
(mid: Validation[MidF, MidS]) = mid match {
case Success(s) =>
next.processWithProgress(progress)(s)
case Failure(f) =>
next.moveProgress(progress)
f.failure
}
protected def moveProgress(progress: MultiPhasedProgress) {
progress.moveProgress(phasesCount)
}
}
private[phase] class ChainedValidatingPhase[-In, MidF, MidS, +OutS](prev: ValidatingPhase[In, MidF, MidS],
next: ValidatingPhasesChain[MidS, MidF, OutS])
extends ValidatingPhasesChain[In, MidF, OutS] {
def processWithProgress(progress: MultiPhasedProgress) = {
val processPrevWrapped = processWrapped(prev.name, prev.process)(progress)
processPrevWrapped andThen processIfSuccessOrMoveProgress(progress)(next)
}
val phasesCount = 1 + next.phasesCount
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment