Have many keys to lookup values.
Let's compare
DictYou want the
πwhere theπis1?
< π= 0, π = π³ |
β < π= 1, π = π |
< π= 2, π = π |
(π is unique)Going through while comparing your
π.
π where `π` is `1`KeysDictYou want the pair where
ποΈis1and the pair whereπis0?
β < π= 0, π = π, ποΈ= 2 >
< π= 2, π = π³, ποΈ= 0 >
< π= 1, π = π, ποΈ= 1 > β
(π & ποΈ are unique)Going through while checking every pair, if
ποΈis equal, then, ifπis equal.
π= 1, ποΈ= 1 where ποΈ is 1 π= 0, ποΈ= 2 where π is 0Β
KeysDicttype alias CasedLetter=
{ lowercase: Char
, uppercase: Char
}
lowerUppercaseLetters: KeysDict CasedLetter
lowerUppercaseLetters=
KeysDict.empty [ unique .lowercase, unique .uppercase ]
|>KeysDict.putIn { lowercase= 'a', uppercase= 'A' }
|>KeysDict.putIn { lowercase= 'b', uppercase= 'B' }
|>KeysDict.putIn { lowercase= 'c', uppercase= 'C' }
uppercase char=
KeysDict.access .lowercase char
lowerUppercaseLetters
|>Maybe.map .uppercasetry in the ellie for the example cased letters (always a version behind)
type Element=
Hydrogen
| Helium
elementAtomicNumberKeysDict=
KeysDict.fromList
[ unique .atomicNumber, unique .element ]
[ { element= Hydrogen, atomicNumber= 1 }
, { element= Helium, atomicNumber= 2 }
]
atomicNumberByElement=
KeysDict.toDict .element .atomicNumber
elementAtomicNumberKeysDictYou have pairs that belong together:
brackets=
KeysDict.empty [ unique .opening, unique .closing ]
|>KeysDict.putIn { opening= '(', closing= ')' }
|>KeysDict.putIn { opening= '{', closing= '}' }
typeChar character=
case KeysDict.access .open character brackets of
Just { closed }->
String.fromList [ character, closed ]
Nothing->
case KeysDict.access .closed character brackets of
Just \{ open }->
String.fromList [ open, character ]
Nothing->
String.fromChar character
"Typing (: " ++(typeChar '(') ++". Even }: " ++(typeChar '}')Β
KeysDictanswers=
KeysDict.fromList [ unique .youSay ]
[ { youSay= "Hi", answer= "Hi there!" }
, { youSay= "Bye", answer= "Ok, have a nice day and spread some love." }
, { youSay= "How are you", answer= "I don't have feelings :(" }
, { youSay= "Are you a robot"
, answer= "I think the most human answer is 'Haha... yes'"
}
]please use a Dict where it is more appropriate: Dicts are for one-way access
englishGerman=
KeysDict.fromList []
[ { english= "elm", german= "Ulme" }
, { english= "git", german= "Schwachkopf" }
, { german= "RΓΌster", english= "elm" }
]A KeysDict is only effective, when there is only one unique key.
Please take a look at elm-bidict instead!
Similar to the previous example:
partners=
KeysDict.empty [ unique .partner, unique .partnerOfPartner ]
|>KeysDict.putIn { partner= "Ann", partnerOfPartner= "Alan" }
|>KeysDict.putIn { partner= "Alex", partnerOfPartner= "Alastair" }
|>KeysDict.putIn { partner= "Alan", partnerOfPartner= "Ann" }
--wait, this is no duplicate and is insertedA KeysDict ony makes sense, when the keys describe something different.