Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ianmackenzie/elm-units-interval
Version of elm-interval based on elm-units
https://github.com/ianmackenzie/elm-units-interval
elm interval units
Last synced: 2 months ago
JSON representation
Version of elm-interval based on elm-units
- Host: GitHub
- URL: https://github.com/ianmackenzie/elm-units-interval
- Owner: ianmackenzie
- License: mpl-2.0
- Created: 2018-12-16T21:40:17.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-04-19T23:54:24.000Z (over 3 years ago)
- Last Synced: 2024-08-01T13:23:41.997Z (4 months ago)
- Topics: elm, interval, units
- Language: Elm
- Homepage:
- Size: 67.4 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Authors: AUTHORS
Awesome Lists containing this project
- awesome-ccamel - ianmackenzie/elm-units-interval - Version of elm-interval based on elm-units (Elm)
README
# elm-units-interval
This package lets you work with ranges of values (intervals) based on the
`Quantity` type from [`elm-units`][elm-units]. You can do things like:- Check if a given value is within an interval
- Construct intervals from lists of values or other intervals
- Find the intersection of two intervals
- Perform [arithmetic][interval-arithmetic] on intervals```elm
import Quantity.Interval as Interval exposing (Interval)
import Angle exposing (Radians)
import Pixels exposing (Pixels)angleRange : Interval Float Radians
angleRange =
Interval.fromEndpoints
( Angle.degrees 0, Angle.degrees 180 )widthRange : Interval Int Pixels
widthRange =
Interval.fromEndpoints
( Pixels.int 100, Pixels.int 300 )
```Various functionality is included for constructing intervals (including as the
union or intersection of other intervals) and checking for overlap, intersection
or containment:```elm
import Quantity.Interval as Interval exposing (Interval)
import Length
import DurationdistanceInterval =
Interval.fromEndpoints
( Length.meters 10, Length.meters 20 )Interval.endpoints distanceInterval
--> ( Length.meters 10, Length.meters 20 )Interval.hull
(Length.feet 5)
[ Length.feet 3
, Length.feet 2
, Length.feet 4
]
--> Interval.fromEndpoints
--> ( Length.feet 2, Length.feet 5 )Interval.aggregate2
(Interval.fromEndpoints
( Duration.minutes 1
, Duration.minutes 2
)
)
(Interval.fromEndpoints
( Duration.minutes 3
, Duration.minutes
)
)
--> Interval.fromEndpoints
--> ( Duration.minutes 1, Duration.minutes 5 )Interval.intersection
(Interval.fromEndpoints
( Duration.hours 1
, Duration.hours 3
)
)
(Interval.fromEndpoints
( Duration.hours 2
, Duration.hours 5
)
)
--> Just <|
--> Interval.fromEndpoints
--> ( Duration.hours 2
--> , Duration.hours 3
--> )Interval.fromEndpoints
( Angle.radians 0, Angle.radians pi )
|> Interval.contains (Angle.degrees 90)
--> TrueInterval.fromEndpoints
( Angle.radians 0, Angle.radians pi )
|> Interval.contains (Angle.degrees 270)
--> False
```Most functionality is contained in the [`Quantity.Interval`](Quantity-Interval)
module, but some functionality specific to particular kinds of intervals is
contained in [`Angle.Interval`](Angle-Interval) and [`Temperature.Interval`](Temperature-Interval).[elm-interval]: https://package.elm-lang.org/packages/ianmackenzie/elm-interval/latest/
[elm-units]: https://package.elm-lang.org/packages/ianmackenzie/elm-units/latest/
[interval-arithmetic]: https://en.wikipedia.org/wiki/Interval_arithmetic