2/27/2017 - 8:14 PM

State Monad

State Monad

import scalaz._
import Scalaz._

//If you have some state(variable). and you are performing so many operations
//with that state().
//Instead of using some mutable varibale, we can sort of use State.

val test1 = for {
  a <- init[Int]
  _ <- modify[Int](_ + 1)
  b <- init[Int]
} yield (a, b)

//(1, (0,1))
//The first value is the state value. and the second is what we are returning.