left & right as a value-pair
Create 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=
Dict.empty
|>Dict.insert 'a' 'A'
|>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' ) --+ { left= 'b', right= 'B' }
, ( 'a', 'A' ) --+ { left= 'a', right= 'A' }
, ( 'b', 'C' ) --ignored, as the left value already exists
, ( 'c', 'A' ) --ignored, as the right value already exists
, ( 'c', 'C' ) --+ { left= 'c', right= 'C' }
]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=
Dict.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' }
|>insert { left= 'c', right= 'C' }
upperCase char=
rightOf char casedLettersHow many pairs there are.
size empty --0
size
(fromList
(List.range 0 41 |>List.map (\i-> ( i, i )))
)
--42Put in a left-right-Pair
If either value is already present, the dict is unchanged.
empty
|>insert { left= "(", right= ")" }
|>insert { right= "fire", left= "water" }
--fromList
-- [ ( "(", ")" ) ( "water", "fire" ) ]Merge 2 PairDicts.
If a value on the left or right is present, prefer the second dict.
numberOperatorNames=
fromList
[ ( '+', "plus" )
, ( '-', "minus" )
]
boolOperatorNames=
fromList
[ ( '∧', "and" )
, ( '∨', "or" )
]
operatorNames=
union numberOperatorNames boolOperatorNamesremove left-right pair.
If left does not exist, the PairDict is unchanged
empty
|>insert "(" ")"
|>removeLeft "("
--emptyremove left-right pair.
If right does not exist, the PairDict is unchanged
empty
|>insert "(" ")"
|>removeRight ")"
--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 highest left to lowest left
brackets=
fromList
[ ( '(', ')' )
, ( '{', '}' )
]
openingAndClosing=
foldl
(\{ left, right } acc->
String.fromList [ left, right ]
)
[]
--[ "{}", "()" ]Reduce the left-right Pairs from lowest left to highest left
brackets=
fromList
[ ( '(', ')' )
, ( '{', '}' )
]
openingAndClosing=
brackets
|>foldl
(\{ left, right } acc->
acc ++[ String.fromList [ left, right ] ]
)
[]
--[ "()", "{}" ]map pairs
digitNames=
fromList
[ ( 0, "zero" )
, ( 1, "one" )
]
mathSymbolNames=
digitNames
|>map
(\{left,right}->
{ left= String.fromInt left
, right= right
}
)
|>insert { left= "+", right= "plus" }
Want to look up value-pairs from the left or the right?
Example: cased letters