StmContainers.Map

stm-containers-1.2.1: Containers for STM

Safe Haskell | None
Language | Haskell2010

StmContainers.Map

Synopsis

- data Map key value
- new :: STM (Map key value)
- newIO :: IO (Map key value)
- null :: Map key value -> STM Bool
- size :: Map key value -> STM Int
- focus :: Hashable key => Focus value STM result -> key -> Map key value -> STM result
- lookup :: Hashable key => key -> Map key value -> STM (Maybe value)
- insert :: Hashable key => value -> key -> Map key value -> STM ()
- delete :: Hashable key => key -> Map key value -> STM ()
- reset :: Map key value -> STM ()
- unfoldlM :: Map key value -> UnfoldlM STM (key, value)
- listT :: Map key value -> ListT STM (key, value)
- listTNonAtomic :: Map key value -> ListT IO (key, value)

# Documentation

data Map key value #

Hash-table, based on STM-specialized Hash Array Mapped Trie.

new :: STM (Map key value) #

Construct a new map.

newIO :: IO (Map key value) #

Construct a new map in IO.

This is useful for creating it on a top-level using `unsafePerformIO`, because using `atomically` inside `unsafePerformIO` isn't possible.

null :: Map key value -> STM Bool #

Check, whether the map is empty.

size :: Map key value -> STM Int #

Get the number of elements.

focus :: Hashable key => Focus value STM result -> key -> Map key value -> STM result #

Focus on a value by the key.

This function allows to perform composite operations in a single access to the map's row. E.g., you can look up a value and delete it at the same time, or update it and return the new value.

lookup :: Hashable key => key -> Map key value -> STM (Maybe value) #

Look up an item.

insert :: Hashable key => value -> key -> Map key value -> STM () #

Insert a value at a key.

delete :: Hashable key => key -> Map key value -> STM () #

Delete an item by a key.

reset :: Map key value -> STM () #

Delete all the associations.

unfoldlM :: Map key value -> UnfoldlM STM (key, value) #

Stream the associations actively.

Amongst other features this function provides an interface to folding.

listT :: Map key value -> ListT STM (key, value) #

Stream the associations passively.

listTNonAtomic :: Map key value -> ListT IO (key, value) #

Stream the associations passively. Data may be inconsistent/out of date.