Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/russelldavies/elm-range
Model and operate on a range of values in Elm
https://github.com/russelldavies/elm-range
elm
Last synced: about 7 hours ago
JSON representation
Model and operate on a range of values in Elm
- Host: GitHub
- URL: https://github.com/russelldavies/elm-range
- Owner: russelldavies
- License: bsd-3-clause
- Created: 2018-09-08T14:34:39.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-02-13T07:05:15.000Z (almost 3 years ago)
- Last Synced: 2023-08-08T20:40:04.609Z (over 1 year ago)
- Topics: elm
- Language: Elm
- Homepage: https://package.elm-lang.org/packages/russelldavies/elm-range/latest/
- Size: 190 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# russelldavies/elm-range
Model and operate on a range of values in Elm.
```elm
Result.map2 Range.merge
(Range.fromString Range.types.int "[1,5]")
(Range.fromString Range.types.int "(4,10]")
|> Result.map Range.toString -- Ok "[1,11)"
```## Overview
The concept of a range is inspired from PostgreSQL's [Range
Types](https://www.postgresql.org/docs/current/rangetypes.html):> Range types are data types representing a range of values of some element
> type (called the range's *subtype*). For instance, ranges of `timestamp`
> might be used to represent the ranges of time that a meeting room is
> reserved. In this case the data type is `tsrange` (short for “timestamp
> range”), and `timestamp` is the subtype. The subtype must have a total order
> so that it is well-defined whether element values are within, before, or
> after a range of values.
>
> Range types are useful because they represent many element values in a single
> range value, and because concepts such as overlapping ranges can be expressed
> clearly. The use of time and date ranges for scheduling purposes is the
> clearest example; but price ranges, measurement ranges from an instrument,
> and so forth can also be useful.## Usage
When creating a range, either from a string or directly from values, you will
need to specify a type. This library provides a few for `Int`, `Float`,
`String`, and `Time.Posix` in the `Range.types` record. If you need a custom
one, you will need to write your own `TypeConfig` (essentially a typeclass).