https://github.com/eeue56/elm-default-dict
A dict implementation which allows you to provide a default value to use
https://github.com/eeue56/elm-default-dict
Last synced: 19 days ago
JSON representation
A dict implementation which allows you to provide a default value to use
- Host: GitHub
- URL: https://github.com/eeue56/elm-default-dict
- Owner: eeue56
- License: bsd-3-clause
- Created: 2015-10-31T14:06:28.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-11-16T15:33:39.000Z (over 8 years ago)
- Last Synced: 2025-03-28T13:12:11.200Z (about 1 month ago)
- Language: Elm
- Homepage:
- Size: 20.5 KB
- Stars: 1
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# elm-default-dict
Use default dictionaries in Elm!
```elm
-- create a default dictionary with the value 0
ages : DefaultDict String Int
ages =
DefaultDict.empty 0-- equal to 5
mikesAge =
DefaultDict.insert "Mike" 5 ages
|> DefaultDict.get "Mike"-- equal to 0
someoneElse =
DefaultDict.get "David" ageseveryonesAges : DefaultDict String Int
everyonesAges =
DefaultDict.fromList
100
[ ("Mike", 5)
, ("David", 0)
, ("Tommy", 19)]-- equal to 100
leesAge =
DefaultDict.get "Lee" everyonesAges
```## When should I use this?
Whenever you want a dictionary to have a default value. The implementation is roughly
70% identical to core's Dict, meaning that the API mirrors it exactly.The increased size overhead is `4 * size of v`. v is stored on each of the `RBEmpty` leafs.
## Interesting notes
Due to the way that `toString` works internally, our `DefaultDict` can get pretty printing for free by using the same types used to implement `Dict`.