I just released <Measured>. A library that makes u...
# science
a
I just released Measured. A library that 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.
Copy code
val velocity     = 5 * meters / seconds
val acceleration = 9 * meters / (seconds * seconds)
val time         = 1 * minute

//  d = vt + ½at²
val distance     = velocity * time + 1.0/2 * acceleration * time * time

println(distance                       ) // 16500 m
println(distance * 1000 `as` kilometers) // 16.5 km
println(distance * 1000 `as` miles     ) // 10.25262467191601 mi

println(5 * miles / hours `as` meters / seconds) // 2.2352 m/s
Try it out and provide feedback. (edited) Thread in Slack Conversation