Created
October 14, 2015 05:55
-
-
Save blast-hardcheese/b42777802cc7bd11c19b 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
import shapeless._ | |
sealed trait Animal | |
case class Point(x: Double, y: Double) | |
case class Color(r: Byte, g: Byte, b: Byte) | |
case class Turtle(position: Point, heading: Double, color: Color) extends Animal | |
case class Cat(position: Point, color: Color) extends Animal | |
implicit val turtlePosition = lens[Turtle].position | |
implicit val catPosition = lens[Cat].position | |
def updatePosition[T <: Animal](animal: T, pos: Point)(implicit ev: Lens[T, Point]) = ev.set(animal)(pos) | |
updatePosition(t0, Point(0.0, 0.0)) | |
updatePosition(c0, Point(0.0, 0.0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment