All Projects β†’ kunalsheth β†’ Units Of Measure

kunalsheth / Units Of Measure

Licence: mit
Type-safe dimensional analysis and unit conversion in Kotlin.

Programming Languages

kotlin
9241 projects
dsl
153 projects

Projects that are alternatives of or similar to Units Of Measure

Safe Units
Type-safe TypeScript units of measure πŸ‘·πŸ“
Stars: ✭ 137 (+98.55%)
Mutual labels:  typesafe, units-of-measure
Strictyaml
Type-safe YAML parser and validator.
Stars: ✭ 836 (+1111.59%)
Mutual labels:  typesafe
numberfmt
Number formatting using a text pattern and native Intl.NumberFormat()
Stars: ✭ 17 (-75.36%)
Mutual labels:  units-of-measure
Unitful.jl
Physical quantities with arbitrary units
Stars: ✭ 279 (+304.35%)
Mutual labels:  units-of-measure
pyroclastic
Functional dataflow through composable computations
Stars: ✭ 17 (-75.36%)
Mutual labels:  typesafe
Units
A compile-time enabled Modern C++ library that provides compile-time dimensional analysis and unit/quantity manipulation.
Stars: ✭ 365 (+428.99%)
Mutual labels:  units-of-measure
graphql-typed-client
Strongly typed GraphQL client for .NET
Stars: ✭ 16 (-76.81%)
Mutual labels:  typesafe
Mizur
Mizur is a tool to simplify the handling of units, and units coercion/mapping. (it is an evolution of Abacus)
Stars: ✭ 34 (-50.72%)
Mutual labels:  typesafe
Unitsnet
Makes life working with units of measurement just a little bit better.
Stars: ✭ 641 (+828.99%)
Mutual labels:  units-of-measure
trembita
Model complex data transformation pipelines easily
Stars: ✭ 44 (-36.23%)
Mutual labels:  typesafe
event-bus
Typesafe cross-platform pubsub event bus ensuring reliable communication between fragments and micro frontends.
Stars: ✭ 15 (-78.26%)
Mutual labels:  typesafe
typesql
TypeSQL - Generate Typescript API from raw MySQL queries. Compatible with Deno and Node.
Stars: ✭ 37 (-46.38%)
Mutual labels:  typesafe
Jet
Type safe SQL builder with code generation and automatic query result data mapping
Stars: ✭ 373 (+440.58%)
Mutual labels:  typesafe
UnitfulAstro.jl
An extension of Unitful.jl for astronomers.
Stars: ✭ 18 (-73.91%)
Mutual labels:  units-of-measure
Hoodie
Hoodie is a type safe wrapper around jersey http client
Stars: ✭ 22 (-68.12%)
Mutual labels:  typesafe
circe-config
Yet another Typesafe config Scala wrapper powered by circe
Stars: ✭ 18 (-73.91%)
Mutual labels:  typesafe
poetimizely
Generate Kotlin type safe accessors for Optimizely experiments and features
Stars: ✭ 17 (-75.36%)
Mutual labels:  typesafe
Length.js
πŸ“ JavaScript library for length units conversion.
Stars: ✭ 292 (+323.19%)
Mutual labels:  units-of-measure
Physunits Ct Cpp11
A small C++11, C++14 header-only library for compile-time dimensional analysis and unit/quantity manipulation and conversion
Stars: ✭ 67 (-2.9%)
Mutual labels:  units-of-measure
Barril
Python package to manage units for physical quantities
Stars: ✭ 25 (-63.77%)
Mutual labels:  units-of-measure

units-of-measure

Type-safe dimensional analysis and unit conversion in Kotlin.

demo image


Project Status

Stable and safe for production.

Building UOMs for the first time is quite slow on the latest Kotlin compiler versions (1.3.70+). To improve compile times, UOMs 7.0.0+ will be repackaged as an Ξ›rrow Meta plugin.

Usage

Take a look at the project website for installation and usage: http://units.kunalsheth.info

You can also take a look at this sample project for a complete gradle setup and to learn about some of the more advanced features.


More sample code:

val mass1 = 3.kilo(Gram)
val mass2 = 14.Ounce
val sum = mass1 + mass2
// mass1 + 3.Days // will not compile

assert(sum in 7.5.Pound `Β±` 1.Ounce)
assert(sum in 3.3.kilo(Gram)..7.5.Pound) // this works too
// assert(sum in 7.4.Kilowatts..7.5.Pounds) // will not compile

val ratio = 2.Foot / 1.Metre
assert(ratio in 60.Percent `Β±` 5.Percent)
assert(ratio.Percent.toInt() in 55..65)


assert(1.kilo(Gram) == 1000.Gram)
assert(10.milli(Metre) == 1.centi(Metre))
assert(60000.milli(Second) == 1.Minute)


assert(420.Degree % 1.Turn in 60.Degree `Β±` 1.Degree)


val speed = 65.Mile / Hour
val time = 27.Minute
val distance = speed * time
val aBitFaster = distance / (time - 30.Second)

assert(distance == time * speed)
assert(distance in 29.Mile..30.Mile)
assert(distance in 30.Mile..29.Mile) // this works too
assert(aBitFaster in speed..(speed + 4.kilo(Metre) / Hour))


val threshold = 0.001.Foot / Second / Second
sequenceOf(0, 1, 4, 9, 16, 25).map { it.Foot }
        .derivative(::p)
        .derivative(::p)
        .zipWithNext { a, b -> a in b `Β±` threshold }
        .forEach { assert(it) }
// support for generic programming
fun <Q : Quan<Q>, DQDT : Quan<DQDT>> Sequence<Q>.derivative(p: (Q, `Γ·`, T) -> DQDT) = timeSeq()
        .zip(this)
        .zipWithNext { (x1, y1), (x2, y2) -> p(
                (y1 - y2), `Γ·`, (x1 - x2)
        ) }

Background

Type-safe dimensional analysis and unit conversion can be extremely beneficial to a team. From personal experience, using type-safe calculations result in:

  • Faster Development β€” IDE autocomplete provides meaningful predictions, rather than just listing every number in scope.
  • Cleaner Code β€” Variable names will be of a reasonable length now that unit information is documented by the type.
  • Higher Confidence β€” All unit/dimension related bugs will show up at compile time. Debugging is less difficult and time-consuming.

units-of-measure's novel, metaprogramming approach to the problem makes it:

  1. Incredibly Extendable β€” Adding new functionality is as simple as adding a line to your build file. No tedious "hand-coding" is required.
  2. Small β€” You only generate what you need. You are not forced to bundle every conceivable unit, quantity, and dimension with your app.
  3. Bug Resistant β€” Programming by hand is error prone and time-consuming. Code generation can ensure correctness.

Todo List

  • [x] Make it work.
  • [x] Generate implicit relationships as well.
  • [x] Make annotations easier to write and manage.
  • [x] Add support for unit conversions.
  • [x] Add docs. (http://units.kunalsheth.info)
  • [x] Add metric prefixes.
  • [x] Multiplatform.
  • [x] Stronger support for generic use (Quantity<This, IntegralOfThis, DerivativeOfThis>)
  • [x] * and Γ· singleton types for even safer proof-passing.
  • [x] Publish on Gradle Plugin Portal.
  • [ ] Document serialization functionality.
  • [ ] Optimize for faster compilation and runtime.
  • [ ] Benchmark performance hit in contrast to primitives. (Can someone help me with this?)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].