Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.37 KB | None | 0 0
  1. final class WalkDistance(val x: Int) extends AnyVal {
  2.     def get: Int = x
  3.     def isEmpty = x < 3000
  4.   }
  5.  
  6. final class CarDistance(val x: Int) extends AnyVal {
  7.     def get: Int = x / 1000
  8.     def isEmpty = x >= 3000
  9.   }
  10.  
  11. def select(distance: Int) = distance match{
  12.     case WalkDistance(w) => s"I will walk ${w} meters}
  13.     case CarDistance(c) => s"I will drive ${x} km}
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement