Last active
August 29, 2015 14:04
-
-
Save aryairani/58175e2f15bb3d11a9a7 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 ET { | |
import scalaz.Lens | |
case class Foo[A](a: A, i: Int) | |
object Foo { | |
def a[A]: Lens[Foo[A],A] = Lens.lensg(x => y => x.copy(a=y), _.a) | |
def i1[A]: Lens[Foo[A],Int] = Lens.lensg(x => y => x.copy(i=y), _.i) | |
def i2: Lens[Foo[A] forSome {type A},Int] = Lens.lensg(x => y => x.copy(i=y), _.i) | |
def i3: Lens[Foo[_],Int] = Lens.lensg(x => y => x.copy(i=y), _.i) | |
} | |
val myFoo = Foo("hello", 3) | |
import Foo._ | |
println(myFoo) | |
println(a.set(myFoo, "goodbye")) | |
println(i1.set(myFoo, 4)) | |
println(i2.set(myFoo, 5)) | |
println(i3.set(myFoo, 6)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment