Skip to content

Instantly share code, notes, and snippets.

@soc
Created April 7, 2012 00:39
Show Gist options
  • Select an option

  • Save soc/2324287 to your computer and use it in GitHub Desktop.

Select an option

Save soc/2324287 to your computer and use it in GitHub Desktop.
object UnitExample extends App {
val mass: Mass[Double] = 4.0 kg
val longMass: Mass[Long] = (4.0 kg) asLong
val length: Length[Int] = (5 m) * 3
val time: Time[Int] = 1 s
val time2: Time[Int] = time + time
val time3 = time2 + (1 minute)
val temperature: Temperature[BigDecimal] = BigDecimal("22.22") k
val speed: Speed[Int] = length / time
val area: Area[Int] = length * length
val volume: Volume[Int] = (23 m) * (1 m) * (1 m)
val smallVolume = (volume asDouble) / 12.0
val area2: Area[Int] = volume / (23 m)
val accel: Acceleration[Double] = (10.0 m) / ((2.0 s) * (1.0 s))
val accelNum: Double = accel toDouble
println(mass.niceString)
println(length.niceString)
println(temperature.niceString)
println(time.niceString)
println(time2.niceString)
println(time3.niceString)
println(speed.niceString)
println(area.niceString)
println(volume.niceString)
println(smallVolume.niceString)
println(accel.niceString)
}
/*
4.0 kg
15 m
22.22 k
1 s
2 s
62 s
15 m/s
225 m^2
23 m^3
1.9166666666666667 m^3
5.0 m/s^2
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment