Skip to content

Instantly share code, notes, and snippets.

@vmarquez
Last active August 29, 2015 14:16
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 vmarquez/64482fd3c4142d465b8d to your computer and use it in GitHub Desktop.
Save vmarquez/64482fd3c4142d465b8d to your computer and use it in GitHub Desktop.
object Test {
trait BlahConfig[A <: BlahConfig[A]] {
val server: Int
def updateCache(l: List[Int]): A
}
def doBlahStuff[A <: BlahConfig[A]](i: Int) = State[A, Int]( c => (c.updateCache(List(i)), c.server) )
trait FooConfig[A <: FooConfig[A]] {
def password: String
}
def doFooStuff[A <: FooConfig[A]](s:String) = State[A, String](c =>(c, c.password))
//CONCRETE CONFIG
case class RConfig(s: Int, p: String, cache: List[Int]) extends BlahConfig[RConfig] with FooConfig[RConfig] {
val password = p
val server = s
def updateCache(l: List[Int]) = this.copy(cache = l ::: cache)
}
val res = for {
str <- doSomeStuff[RConfig]("blah")
i <- doStuff[RConfig](2)
} yield i
res(RConfig(1, "asdf", List[Int]()))
}
@vmarquez
Copy link
Author

vmarquez commented Mar 7, 2015

thanks to @emrys and @dibblego who informed me lenses could solve the issue by zooming, I was able to redo this in a much nicer way:

https://gist.github.com/vmarquez/bac38b6605359124bb83

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment