Created
June 2, 2016 06:24
-
-
Save anonymous/f90ca2bffd5461b25063fc88d43bb1cd to your computer and use it in GitHub Desktop.
the description for this gist
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
object InterpretOpt extends (Instruction ~> Option) { | |
import Computations._ | |
val nonNegative: (Position) => Option[Position] = { | |
p => if (p.x >= 0 &&p.y >= 0) Some(p) else None | |
} | |
override def apply[A](fa: Instruction[A]) = fa match { | |
case Forward(p, length) => nonNegative(forward(p, length)) | |
case Backward(p, length) => nonNegative(backward(p, length)) | |
case RotateLeft(p, degree) => Some(left(p, degree)) | |
case RotateRight(p, degree) => Some(right(p, degree)) | |
case ShowPosition(p) => Some(println(s"showing position $p")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment