Created
October 16, 2016 15:07
-
-
Save danslapman/f9011969f0b67bbc2528ec7b266295de to your computer and use it in GitHub Desktop.
StateT as a monad
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
import scala.concurrent.ExecutionContext.Implicits.global | |
import scala.concurrent.duration._ | |
import scala.concurrent.{Await, Future} | |
import scalaz.{Monad, StateT} | |
import scalaz.std.AllInstances._ | |
object Test extends App { | |
implicit val ifsmi = StateT.stateTMonadState[Int, Future] | |
import ifsmi.{get, put} | |
val algo = for { | |
_ <- ifsmi.whileM_(get map (_ < 10), | |
for { | |
i <- get | |
_ <- put(i + 1) | |
} yield () | |
) | |
v1 <- get | |
} yield v1 | |
println(Await.result(algo.run(0), 10.seconds)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment