I've just implement direction enum
object Direction extends Enumeration {
type Direction = Value
val Up, Right, Down, Left = Value
val pairs = HashSet() ++ List((HashSet() ++ List(Up, Down)), (HashSet() ++ List(Right, Left)))
def isOpposite(one: Direction, other: Direction): Boolean = {
pairs.contains(HashSet() ++ List(one, other))
}
}
Usages
direction match {
case Right => ...
case Left => ...
case Up => ...
case Down => ...
}
if(Direction.isOpposite(d1, d2))...
Can I improve it some how?