Some well known tools carried over from the Dict module, and
others derived from it. Since the members of a dictionary are Boxed, all of
them can be encapsulations of values of different types.
Get the value associated with a key. Successful only if found, and the given function could be applied to it.
boxedDict = Dictionary (Dict.fromList [("one", Integer 1), ("two", Double 3.03)])
mapGet asBool "two" boxedDict == Nothing
mapGet asInt "one" boxedDict == Just 1Boxed is currently holding an encapsulation of said type. Defined mainly as helpers for the Dict's map, filter and partition functions.Insert a key-value pair into a Boxed as a dictionary. Succesful even if
the Boxed target is not even currently holding a dictionary.
boxedDict = Dictionary (Dict.fromList [("one", Str "b"), ("two", Double 3.03)])
insert "tree" (Integer 1) boxedDict == Dictionary (Dict.fromList [("one", Str "b"), ("tree", Integer 1), ("two", Double 3.03)])
insert "tree" (Integer 1) (Str "placeholder") == Dictionary (Dict.fromList [("tree", Integer 1)])Update the value of a boxed dictionary for a specific key with a given function.
boxedDict = Dictionary (Dict.fromList [("one", Str "b"), ("two", Double 3.03)])
modifier = always (Just (Boolean False))
update "two" modifier boxedDict == Dictionary (Dict.fromList [("one", Str "b"), ("two", Boolean False)])Remove a key-value pair from a boxed dictionary.
boxedDict = Dictionary (Dict.fromList [("one", Str "b"), ("two", Double 3.03)])
remove "one" boxedDict == Dictionary (Dict.fromList [("two", Double 3.03)])
remove "three" (Integer 1) == Dictionary (Dict.fromList [])Apply a given function to a boxed dictionary.
boxedDict = Dictionary (Dict.fromList [("one", Str "b"), ("two", Double 3.03)])
apply (Dict.get "two") boxedDict == Just (Double 3.03)
apply (Dict.member "one") boxedDict == True
apply Dict.size boxedDict == 2
apply Dict.isEmpty (Str "d") == True
apply (Dict.map tryString) boxedDict == Dict.fromList [("one",Just "b"),("two",Nothing)]
Returns a
Dictwith only succesful values, resulting from the application of a given function.