You are currently viewing Type-safe Units with Measured

Type-safe Units with Measured

Measured makes units a lot simpler and intuitive to work with. It uses the compiler to enforce correctness and lets you combine units into more complex ones using math operators. It is also extensible, making it easy to define your own units.

val velocity = 5 * meters / seconds val acceleration = 9 * meters / (seconds * seconds) val time = 1 * minutes // d = vt + ½at² val distance = velocity * time + 1.0/2 * acceleration * time * time println(distance ) // 16500 m println(distance `as` kilometers) // 16.5 km println(distance `as` miles ) // 10.25262467191601 mi println(5 * miles / hours `as` meters / seconds) // 2.2352 m/s 

Give it a try. And leave some feedback.

submitted by /u/pusolito
[link] [comments]