Created
November 13, 2012 02:09
-
-
Save arschles/4063509 to your computer and use it in GitHub Desktop.
Map Over a State[ReqRespData, Res[A]]
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
import scalaz._ | |
import Scalaz._ | |
import Probably.A.Lot.More.Shit | |
//this is how you construct a State manually by the way | |
val myState: State[ReqRespData, Res[String]] = state { d: ReqRespData => | |
val myRes: Res[String] = ValueRes("hello world") | |
(d, myRes) | |
} | |
... | |
val myNewState: State[ReqRespData, Res[Boolean]] = myState.map { res: Res[String] => | |
res match { | |
case v @ ValueRes(s) => { | |
if(s.startsWith("aaron rulez")) { | |
v | |
} else { | |
halt(500, "server cannot continue. it doesn't think aaron rulez") | |
} | |
} | |
case _ => halt(400, "some other shit went wrong. it's prob your fault") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment