StmContainers.Bimap

stm-containers-1.2.1: Containers for STM

Safe Haskell | None
Language | Haskell2010

StmContainers.Bimap

Synopsis

- data Bimap leftKey rightKey
- new :: STM (Bimap leftKey rightKey)
- newIO :: IO (Bimap leftKey rightKey)
- null :: Bimap leftKey rightKey -> STM Bool
- size :: Bimap leftKey rightKey -> STM Int
- focusLeft :: (Hashable leftKey, Hashable rightKey) => Focus rightKey STM result -> leftKey -> Bimap leftKey rightKey -> STM result
- focusRight :: (Hashable leftKey, Hashable rightKey) => Focus leftKey STM result -> rightKey -> Bimap leftKey rightKey -> STM result
- lookupLeft :: Hashable leftKey => leftKey -> Bimap leftKey rightKey -> STM (Maybe rightKey)
- lookupRight :: Hashable rightKey => rightKey -> Bimap leftKey rightKey -> STM (Maybe leftKey)
- insertLeft :: (Hashable leftKey, Hashable rightKey) => rightKey -> leftKey -> Bimap leftKey rightKey -> STM ()
- insertRight :: (Hashable leftKey, Hashable rightKey) => leftKey -> rightKey -> Bimap leftKey rightKey -> STM ()
- deleteLeft :: (Hashable leftKey, Hashable rightKey) => leftKey -> Bimap leftKey rightKey -> STM ()
- deleteRight :: (Hashable leftKey, Hashable rightKey) => rightKey -> Bimap leftKey rightKey -> STM ()
- reset :: Bimap leftKey rightKey -> STM ()
- unfoldlM :: Bimap leftKey rightKey -> UnfoldlM STM (leftKey, rightKey)
- listT :: Bimap key value -> ListT STM (key, value)

# Documentation

data Bimap leftKey rightKey #

Bidirectional map. Essentially, a bijection between subsets of its two argument types.

For one value of the left-hand type this map contains one value of the right-hand type and vice versa.

new :: STM (Bimap leftKey rightKey) #

Construct a new bimap.

newIO :: IO (Bimap leftKey rightKey) #

Construct a new bimap in IO.

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

null :: Bimap leftKey rightKey -> STM Bool #

Check on being empty.

size :: Bimap leftKey rightKey -> STM Int #

Get the number of elements.

focusLeft :: (Hashable leftKey, Hashable rightKey) => Focus rightKey STM result -> leftKey -> Bimap leftKey rightKey -> STM result #

Focus on a right value by the left value.

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

focusRight :: (Hashable leftKey, Hashable rightKey) => Focus leftKey STM result -> rightKey -> Bimap leftKey rightKey -> STM result #

Focus on a left value by the right value.

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

lookupLeft :: Hashable leftKey => leftKey -> Bimap leftKey rightKey -> STM (Maybe rightKey) #

Look up a right value by the left value.

lookupRight :: Hashable rightKey => rightKey -> Bimap leftKey rightKey -> STM (Maybe leftKey) #

Look up a left value by the right value.

insertLeft :: (Hashable leftKey, Hashable rightKey) => rightKey -> leftKey -> Bimap leftKey rightKey -> STM () #

Insert the association by the left value.

insertRight :: (Hashable leftKey, Hashable rightKey) => leftKey -> rightKey -> Bimap leftKey rightKey -> STM () #

Insert the association by the right value.

deleteLeft :: (Hashable leftKey, Hashable rightKey) => leftKey -> Bimap leftKey rightKey -> STM () #

Delete the association by the left value.

deleteRight :: (Hashable leftKey, Hashable rightKey) => rightKey -> Bimap leftKey rightKey -> STM () #

Delete the association by the right value.

reset :: Bimap leftKey rightKey -> STM () #

Delete all the associations.

unfoldlM :: Bimap leftKey rightKey -> UnfoldlM STM (leftKey, rightKey) #

Stream associations actively.

Amongst other features this function provides an interface to folding.

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

Stream the associations passively.