A lightweight Dictionary implementation based on Data.Map, part of the Useful module.
So I kinda like dictionaries, but the functions and syntax by default are hardly as elegant as something like python. This isn't a complete solution and nor is it optimal but it's pretty lightweight and pretty and stuff. You get it. It's based off Data.Map so uses a binary tree and therefore the keys have to have some ordering defined over them.
- dict :: Ord k => [(k, a)] -> Map k a
- dictToList :: Map k a -> [(k, a)]
- (#!) :: Ord k => k -> Map k a -> Maybe a
- (#!!) :: Ord k => Map k a -> k -> a
- (#+) :: Ord k => Map k a -> (k, a) -> Map k a
- (#?) :: Ord k => Map k a -> k -> Bool
- (#*?) :: (Eq a, Ord k) => Map k a -> a -> Bool
- (#-) :: Ord k => Map k a -> k -> Map k a
- (#*-) :: (Eq a, Ord k) => Map k a -> a -> Map k a
- (#\\) :: Ord k => Map k a -> Map k b -> Map k a
- (#++) :: Ord k => Map k a -> Map k a -> Map k a
- (#??) :: (Ord k, Eq a) => Map k a -> Map k a -> Bool
- (#?!) :: (Eq a, Ord k) => Map k a -> a -> k
- dictSize :: Map k a -> Int
- mapD :: (a -> b) -> Map k a -> Map k b
- mapDkeys :: Ord k2 => (k1 -> k2) -> Map k1 a -> Map k2 a
- filterD :: Ord k => (a -> Bool) -> Map k a -> Map k a
- filterDkeys :: Ord k => (k -> a -> Bool) -> Map k a -> Map k a
Dictionary creation
dict :: Ord k => [(k, a)] -> Map k aSource
Alias of Data.Map.fromList, takes a list of key value tuples and creates a dictionary out of them.
dict [("hello",1),("there",2)] fromList [("hello",1),("there",2)] dict [] fromList []
dictToList :: Map k a -> [(k, a)]Source
Returns a List of key-value pairs
Dictionary operations
(#+) :: Ord k => Map k a -> (k, a) -> Map k aSource
adds key-value pair to a dictionary. If key is already in dict will update value.
(#*-) :: (Eq a, Ord k) => Map k a -> a -> Map k aSource
Deletes ALL key-pairs from a dictionary given they match a value
(#?!) :: (Eq a, Ord k) => Map k a -> a -> kSource
Returns a the first occurance of a key from a value. Otherwise error.