Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lue-bird/elm-number-safe
number types that aren't opaque
https://github.com/lue-bird/elm-number-safe
elm number percentage type-safe
Last synced: about 1 month ago
JSON representation
number types that aren't opaque
- Host: GitHub
- URL: https://github.com/lue-bird/elm-number-safe
- Owner: lue-bird
- License: mit
- Created: 2023-12-23T01:08:46.000Z (almost 1 year ago)
- Default Branch: main
- Last Pushed: 2024-01-16T22:22:19.000Z (11 months ago)
- Last Synced: 2024-10-20T00:32:55.019Z (2 months ago)
- Topics: elm, number, percentage, type-safe
- Language: Elm
- Homepage: https://dark.elm.dmy.fr/packages/lue-bird/elm-numbers-safe/latest/
- Size: 33.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## [`elm-numbers-safe`](https://dark.elm.dmy.fr/packages/lue-bird/elm-numbers-safe/latest/)... why?
- have types to represent percentages in the intervals `[0;1]`, `[0;1)`, `(0;1]`, `(0;1)`
- replace operations like
```elm
divide : Number -> Number -> Maybe Number
```
with
```elm
operation : Number -> NumberNot0 -> Number
```
- have a common base type for 0-able, non-0, negatable and unsigned numbers so that operations can allow both
- have transparent definitions, aka have "parsed, not validated" data
- no internal operation is "unsafe", in fact there are no real internal operations
- users can safely create arbitrary numbers## TODO
- `Rational` rounding, toFloat, toAtLeast
- `Integer` toAtLeast, divideBy, remainderBy
- complete `Percentage` including 1
- add more arithmetic operations
- change `Percentage` to base 2
- remove `module Decimal` (alternative: to base 2, add `toRational`)