Last active
August 29, 2015 14:16
-
-
Save vmarquez/64482fd3c4142d465b8d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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]())) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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