Last active
August 29, 2015 14:16
-
-
Save vmarquez/bac38b6605359124bb83 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
object Test { | |
import scalaz.{Lens,State} | |
case class BlahConfig(server: Int, l: List[Int]) | |
def doStuff(i: Int) = State[BlahConfig,Int]( c => (c.copy(l = i :: c.l), c.server) ) | |
case class FooConfig(val password: String) | |
def doSomeStuff(i: Int) = State[FooConfig, String](c =>(c, c.password)) | |
//CONCCRETE CONFIG | |
case class RConfig(s: Int, p: String, l: List[Int]) | |
//A way to go from a 'smaller' type to a bigger type | |
val l1 = Lens.lensu[RConfig, BlahConfig]( (a,b) => a.copy(s = b.server, l = b.l), b => BlahConfig(server=b.s, l = b.l)) | |
val l2 = Lens.lensu[RConfig, FooConfig]( (a,b) => a.copy(p = b.password), b => FooConfig(password = b.p)) | |
val res = for { | |
a <- doStuff(2).zoom(l1) | |
b <- doSomeStuff(a).zoom(l2) | |
} yield a + b | |
res(RConfig(1, "asdf", List(1))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment