Skip to content

Instantly share code, notes, and snippets.

@blast-hardcheese
Created October 14, 2015 05:55
Show Gist options
  • Save blast-hardcheese/b42777802cc7bd11c19b to your computer and use it in GitHub Desktop.
Save blast-hardcheese/b42777802cc7bd11c19b to your computer and use it in GitHub Desktop.
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