https://github.com/bburdette/typed-collections
simple typed layers over standard elm collections
https://github.com/bburdette/typed-collections
Last synced: 2 months ago
JSON representation
simple typed layers over standard elm collections
- Host: GitHub
- URL: https://github.com/bburdette/typed-collections
- Owner: bburdette
- License: mit
- Created: 2018-08-31T14:26:18.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-07-17T18:27:45.000Z (almost 6 years ago)
- Last Synced: 2025-01-21T19:51:14.707Z (4 months ago)
- Language: Elm
- Size: 16.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Typed Containers
Simple layers over the standard Elm containers (Dict and Set), that allow
more types of keys than just 'comparable'. When you create the TDict or
TSet, you must supply conversion functions to go from your key types to
'comparable' and back.This gives you a little extra type safety, at the cost of a little extra
hassle.Herer's an example where you have types that are really just comparables
underneath, but you want to keep them segregated for safety:```elm
-- both types are floats, but we don't want to mix the
-- values together accidentally.
type Kilos =
Kilos Float
type Pounds =
Pounds Float-- Create a TSet with the empty function, which takes two
-- conversion functions as arguments. It can be convenient
-- to create a canonical empty TSet for a certain type:
emptyKiloSet =
TSet.empty
(\(Kilos n) -> n)
Kilos-- a list of Kilo values.
kilolist = [Kilo 1.0, Kilo 2.0]-- Then to do the equivalent of fromList:
kiloSet = TSet.insertList emptyKiloSet kilolist-- but you can't put the kilolist into a pounds Set.
emptyPoundSet =
TSet.empty
(\(Pounds n) -> n)
Pounds
TSet.insertList emptyPoundSet kilolist -- type error!```