Skip to content

Instantly share code, notes, and snippets.

@mrcmatuszak
Created May 25, 2016 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrcmatuszak/0d37a2af3f8c2982ba941fbfb5687147 to your computer and use it in GitHub Desktop.
Save mrcmatuszak/0d37a2af3f8c2982ba941fbfb5687147 to your computer and use it in GitHub Desktop.
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