Last active
August 29, 2015 14:04
-
-
Save arkadius/daa9151dd5df5008ebc2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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