Skip to content

Instantly share code, notes, and snippets.

@aryairani
Last active August 29, 2015 14:04
Show Gist options
  • Save aryairani/58175e2f15bb3d11a9a7 to your computer and use it in GitHub Desktop.
Save aryairani/58175e2f15bb3d11a9a7 to your computer and use it in GitHub Desktop.
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