Skip to content

Instantly share code, notes, and snippets.

@arschles
Created November 13, 2012 02:09
Show Gist options
  • Save arschles/4063509 to your computer and use it in GitHub Desktop.
Save arschles/4063509 to your computer and use it in GitHub Desktop.
Map Over a State[ReqRespData, Res[A]]
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