Skip to content

Instantly share code, notes, and snippets.

@jedws
Created July 12, 2011 07:35
Show Gist options
  • Save jedws/1077561 to your computer and use it in GitHub Desktop.
Save jedws/1077561 to your computer and use it in GitHub Desktop.
sealed trait Heading {
val turn = Turn(this) _
}
case object N extends Heading
case object S extends Heading
case object E extends Heading
case object W extends Heading
object Turn {
def apply(h: Heading)(t: Turn) = t(h)
}
sealed trait Turn extends (Heading => Heading)
case object Left extends Turn {
def apply(h: Heading) = h match {
case N => W
case E => N
case S => E
case W => S
}
}
case object Right extends Turn {
def apply(h: Heading) = h match {
case N => E
case E => S
case S => W
case W => N
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment