An open API service indexing awesome lists of open source software.

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

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!

```