Skip to content

Instantly share code, notes, and snippets.

@mrcmatuszak
Created May 25, 2016 20:48
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/cee890b1f8a0d0a0cb16f69c3e7b06cf to your computer and use it in GitHub Desktop.
Save mrcmatuszak/cee890b1f8a0d0a0cb16f69c3e7b06cf to your computer and use it in GitHub Desktop.
object Counter {
type CounterState = State[Int, Int]
}
trait Counter {
import Counter._
def inc: CounterState = State { s => (s + 1, s + 1) }
}
trait Service {
self: Counter =>
import Counter._
var currentCount: Int = ???
def foo: Int = {
val s = inc.run(???)
currentCount = s.value._1
s.value._2
}
}
trait Service2 {
self: Counter =>
import Counter._
var currentCount: CounterState = ???
def foo: Int = {
val s = inc.run(???)
currentCount = s.value._1
s.value._2
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment