Created
July 12, 2011 07:35
-
-
Save jedws/1077561 to your computer and use it in GitHub Desktop.
This file contains 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
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