Created
May 25, 2016 20:19
-
-
Save mrcmatuszak/0d37a2af3f8c2982ba941fbfb5687147 to your computer and use it in GitHub Desktop.
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
package main | |
import cats.data.State | |
object Example { | |
type CounterState = State[Int, Unit] | |
def inc: CounterState = State { s => (s + 1, ()) } | |
def dec: CounterState = State { s => (s - 1, ()) } | |
} | |
object Main extends App { | |
import Example._ | |
val ex = for { | |
_ <- inc | |
_ <- inc | |
_ <- dec | |
_ <- inc | |
} yield () | |
println(ex.runS(5).value) | |
} | |
// vim: set ts=2 sw=2 et sts=2: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment