using (==) built-in equality is often not useful in the context of association-dicts.
Ignoring insertion order: do these 2 PairDicts have the same size and identical Pairs?
letterCodes=
fromList [ ( 'a', 0 ), ( 'b', 1 ) ]
fancyCompetingLetterCodes=
fromList [ ( 'b', 1 ), ( 'a', 0 ) ]
equal
letterCodes
fancyCompetingLetterCodes
--> TrueCreate a PairDict conveniently from Pair-Tuples. left is the first, right is the second.
If right or left values are given multiple times, the value first in the List is prefered.
lowerToUpperLetters=
AssocList.Dict.empty
|>AssocList.Dict.insert 'a' 'A'
|>AssocList.Dict.insert 'b' 'B'
lowerUpperLetters= fromDict lowerToUpperLettersCreate a PairDict conveniently from Tuples. left is the first, right is the second.
If right or left values are given multiple times, the value first in the List is prefered.
fromList
[ ( 'b', 'B' ) --insert { left= 'b', right= 'B' }
, ( 'a', 'A' ) --insert { left= 'a', right= 'A' }
, ( 'b', 'C' ) --ignored, as the left value already exists
, ( 'c', 'A' ) --ignored, as the right value already exists
, ( 'c', 'C' ) --insert { left= 'c', right= 'C' }
]A Json.Decode.Decoder for PairDicts, encoded by encodePair.
The order of insertion is not reconstructed (see equal)
"""
[
{
\"left\": 2,
\"right\": 22
},
{
\"left\": 1,
\"right\": 11
}
]
"""
|>Decode.decodeString
(decode Decode.int Decode.int)
Ok (fromList [ ( 1, 11 ), ( 2, 22 ) ])
Just the right value if the left value is present in the PairDict, else Nothing
casedLetters=
empty
|>insert { left= 'a', right= 'A' }
|>insert { left= 'b', right= 'B' }
lowerCase char=
leftOf char casedLettersJust the right value if the left value is present in the PairDict, else Nothing
casedLetters=
empty
|>insert { left= 'a', right= 'A' }
|>insert { left= 'b', right= 'B' }
upperCase char=
rightOf char casedLettersHow many pairs there are.
size empty
0
size
(fromList
(List.range 0 41 |>List.map (\i-> ( i, i )))
)
42
Put in a left-right-Pair.
If either value is already present, the PairDict is unchanged.
empty
|>insert { left= 'b', right= 'B' } --puts it in
|>insret { right= 'A', left= 'a' } --puts it in
|>insert { left= 'b', right= 'C' } --ignored, the left value already exists
|>insert { left= 'c', right= 'A' } --ignored, the right value already exists
|>insert { left= 'c', right= 'C' } --puts it inMerge 2 PairDicts.
If a value on the left or right is present, prefer the second dict.
numberNamedOperators=
fromList
[ ( '+', "plus" )
, ( '-', "minus" )
]
customNamedOperators=
fromList
[ ( '∧', "and" )
, ( '∨', "or" )
, ( '-', "negate" )
]
validNamedOperators=
union
custumNamedOperators --has a '-' left
numberOperatorNames --preferred → its '-'-Pair is insertedremove left-right pair.
If left does not exist, the PairDict is unchanged
empty
|>insert "(" ")"
|>removeLeft ")" --unchanged, ")" is not a left value
|>removeLeft "(" --removes { left= "(", right= ")" }
--emptyremove left-right pair.
If right does not exist, the PairDict is unchanged
empty
|>insert { left= "(", right= ")" }
|>removeRight "(" --unchanged, "(" is not a right value
|>removeRight ")" --removes { left= "(", right= ")" }
--emptyvalues on the left
brackets=
fromList [ ( '(', ')' ), ( '{', '}' ) ]
opening= lefts bracketsvalues on the right
brackets=
fromList [ ( '(', ')' ), ( '{', '}' ) ]
closing= rights bracketsWhat has been left → right, right → left.
upperToLower=
fromList
[ ( 'A', 'a' ), ( 'B', 'b' ) ]
lowerToUpper=
upperToLower |>swapLeftRightReduce the left-right Pairs from most recently inserted
to least recently inserted.
A fold in the other direction doesn't exist, as association-Dicts should rarely rely on order (see equal)
brackets=
fromList
[ ( '(', ')' )
, ( '{', '}' )
]
openingAndClosing=
brackets
|>fold
(\{ left, right } acc->
acc ++[ String.fromList [ left, right ] ]
)
[]
[ "{}", "()" ]
map pairs
digitNames=
fromList
[ ( 0, "zero" )
, ( 1, "one" )
]
mathSymbolNames=
digitNames
|>map (Pair.mapLeft String.fromInt)
|>insert { left= "+", right= "plus" }No cost: An association-Dict, which you can access only from the left
casedLetters=
fromList
[ ( 'A', 'a' ), ( 'B', 'b' ) ]
lowerFromUpper=
casedLetters |>dictFromLeftNo cost: An association-Dict, which you can access only from the left
casedLetters=
fromList
[ ( 'A', 'a' ), ( 'B', 'b' ) ]
upperFromLower=
casedLetters |>dictFromRightConvert a PairDict to a Json.Encode.Value.
somePairDict=
empty
|>insert { left= 1, right= 11 }
|>insert { left= 2, right= 22 }
Encode.encode 1
(encode
Encode.int Encode.int
somePairDict
)
"""
[
{
\"left\": 2,
\"right\": 22
},
{
\"left\": 1,
\"right\": 11
}
]
"""
Want to look up value-pairs from the left or the right?
Like assoc-list, a
PairDictallows for anything asleftorrightvalues except for functions and things that contain functions.Example: cased letters