chatter-0.8.0.1: A library of simple NLP algorithms.

Safe HaskellNone

Data.DefaultMap

Synopsis

Documentation

data DefaultMap k v Source

Defaulting Map; a Map that returns a default value when queried for a key that does not exist.

Constructors

DefMap 

Fields

defDefault :: v
 
defMap :: HashMap k v
 

Instances

(Eq k, Eq v) => Eq (DefaultMap k v) 
(Eq k, Read k, Read v, Hashable k) => Read (DefaultMap k v) 
(Show k, Show v) => Show (DefaultMap k v) 
Generic (DefaultMap k v) 
(NFData k, NFData v, Hashable k) => NFData (DefaultMap k v) 
(Arbitrary k, Arbitrary v, Hashable k, Eq k) => Arbitrary (DefaultMap k v) 
(Eq k, Hashable k, Serialize k, Serialize v) => Serialize (DefaultMap k v) 

empty :: v -> DefaultMap k vSource

Create an empty DefaultMap

lookup :: (Eq k, Hashable k) => k -> DefaultMap k v -> vSource

Query the map for a value. Returns the default if the key is not found.

fromList :: (Eq k, Hashable k) => v -> [(k, v)] -> DefaultMap k vSource

Create a DefaultMap from a default value and a list.

keys :: DefaultMap k a -> [k]Source

Access the keys as a list.

elems :: DefaultMap k a -> [a]Source

Access the non-default values as a list.

map :: (a -> a) -> DefaultMap k a -> DefaultMap k aSource

Map a function over the values in a map.

foldl :: (a -> b -> a) -> a -> DefaultMap k b -> aSource

Fold over the values in the map.

Note that this *does* not fold over the default value -- this fold behaves in the same way as a standard foldl

unionWithSource

Arguments

:: forall v k . (Eq k, Hashable k) 
=> (v -> v -> v)

Combine values with this function

-> v

The new map's default value

-> DefaultMap k v

The first map to combine

-> DefaultMap k v

The second map to combine

-> DefaultMap k v 

Compute the union of two maps using the specified per-value combination function and the specified new map default value.