Last active
December 11, 2015 07:08
-
-
Save YoEight/4563594 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def incr(i: Int): EvanderProcess[Int] = (i + 1).pure[EvanderProcess] | |
def apply_n(events: List[Event]): EvanderProcess[List[Event]] = { | |
val sorted = events sortBy (_.v) | |
val received = sorted map (_.v) | |
def msg(expected: Int, got: Int, version: Int) = | |
"Event %d expected, but got %d instead (in events %s from version %d)".format(expected, got, received mkString ", ", version) | |
for { | |
version ← EvanderProcess.getVersion | |
_ ← sorted.traverse(flowProcess) ! (version + 1) | |
} yield sorted | |
} | |
type Version = Int | |
def flowProcess(event: Event): StateT[EvanderProcess, Version, Unit] = { | |
def before(event: Event) = for { | |
x <- init[Version] | |
_ <- LiftM(localVersion(x, go(x, event))) | |
_ <- put(x + 1) | |
} yield() | |
def go(expected: Int, event: Event) = | |
if (expected > event.v) | |
skipped(msg(expected, event.v, version))) | |
else if(expected < event.v) | |
fatalError[Int](msg(expected, event.v, version) | |
else ().pure[EvanderProcess] | |
before(event) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
s/msg/warn/ ?