Skip to content

Instantly share code, notes, and snippets.

View arkadius's full-sized avatar

Arek Burdach arkadius

View GitHub Profile
@arkadius
arkadius / gist:5024653
Created February 24, 2013 17:18
Usage
./journalioMigration oldLogsRoot newLogsRoot
def startService(in: In)(implicit progress: MultiPhasedProgress) {
progress.inPhase("Preparing data") {
prepareData(in)
(...)
}
}
def countPhases(config: Config) = {
val retrievePhases = 2
val validatingPhases = validationService.predictPhases(config)
val generatingPhases = 1
val marshallingPhases = 1
retrievePhases + validatingPhases + generatingPhases + marshallingPhases
}
val chain =
Phase("Preparation") { in: Int => PreparedData(in) } ::
Phase("Validation") { data: PreparedData => ValidatedData(data) } ::
Phase("Execution") { data: ValidatedData => Result(data) } ::
NilChain()
val progress = new MultiPhasedProgress(chain)
val result = progress.run(123)
class Phase[-In, +Out](private[phase] val name: String,
private[phase] val process: In => Out)
object Phase {
def apply[In, Out](name: String)
(process: In => Out) = new Phase(name, process)
}
trait PhasesChain[-In, +Out] extends ChainTransformation[In, Out] {
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)
private def notifyAboutStatus() {
progressHoldingActor ! progressState.status
}
$ scala CastingTest
value: 123
def casted: T = value match {
case t: T => t
case _ => throw new ClassCastException(s"Cannot cast $value to expected type")
}
$ scalac CastingTest.scala
CastingTest.scala:5: warning: abstract type pattern T is unchecked since it is eliminated by erasure
case t: T => t
^
one warning found