Distances micro-DSL - the Scala version

I recently wrote about implementing in Kotlin a very simple DSL for expressing distances. Here is its Scala version:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
object Main {
import Distance._

def main(args: Array[String]) {
val marathon = 42.km + 195.m + 30.cm
println("Marathon " + marathon)
}
}

case class Distance(val m: Double) {
def + (that: Distance) = Distance(this.m + that.m)
}

object Distance {
implicit class IntDistanceExtension(val value: Int) {
def m = new Distance(value.toDouble)

def km = new Distance(value.toDouble * 1000)

def cm = new Distance(value.toDouble/ 100)
}
}