https://github.com/hasnep/roc-units
📏 Type-safe units of measure in Roc
https://github.com/hasnep/roc-units
roc roc-lang units
Last synced: 4 months ago
JSON representation
📏 Type-safe units of measure in Roc
- Host: GitHub
- URL: https://github.com/hasnep/roc-units
- Owner: Hasnep
- License: upl-1.0
- Created: 2024-05-21T21:54:01.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-29T14:28:56.000Z (over 1 year ago)
- Last Synced: 2024-10-29T17:39:23.502Z (over 1 year ago)
- Topics: roc, roc-lang, units
- Language: Roc
- Homepage: https://hasnep.github.io/roc-units
- Size: 68.4 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Roc Units
Type-safe units of measure in Roc.
## Example
Feet, inches and centimeters are all `Length`s, so they can all be added to and converted to each other.
```roc
height = Quantity.feet 5 |> Quantity.add (Quantity.inches 11)
Stdout.line! "Taylor Swift is $(height |> Quantity.toCentimeters |> Num.toStr) centimeters tall."
```
```text
Taylor Swift is 180.34 centimeters tall.
```
But incompatible units cannot be used together.
```roc
isThisAKilometer = Quantity.kilograms 1 |> Quantity.add (Quantity.meters 1)
```
```text
This 2nd argument to add has an unexpected type: ...
```
For a list of all the supported units, see [the documentation](https://hasnep.github.io/roc-units).
## Licence
This project is released under the [UPL licence](./LICENCE) and is partly based on the [elm-units](https://package.elm-lang.org/packages/ianmackenzie/elm-units/latest/) library, which is licenced under the [BSD 3-Clause License](./LICENCE-elm-units).