 | bimap-0.1: Bidirectional mapping between two key types | Contents | Index |
|
|
|
|
|
| Description |
An implementation of bidirectional maps between values of two
key types. A Bimap is essentially a bijection between subsets of
its two argument types.
For functions with an L or R suffix, the letter indicates whether
the parameter type is specialized to the left or right type of
the bimap.
|
|
| Synopsis |
|
| data Bimap a b | | | null :: Bimap a b -> Bool | | | size :: Bimap a b -> Int | | | member :: (Ord a, Ord b) => Either a b -> Bimap a b -> Bool | | | memberL :: (Ord a, Ord b) => a -> Bimap a b -> Bool | | | memberR :: (Ord a, Ord b) => b -> Bimap a b -> Bool | | | notMember :: (Ord a, Ord b) => Either a b -> Bimap a b -> Bool | | | notMemberL :: (Ord a, Ord b) => a -> Bimap a b -> Bool | | | notMemberR :: (Ord a, Ord b) => b -> Bimap a b -> Bool | | | pairMember :: (Ord a, Ord b) => (a, b) -> Bimap a b -> Bool | | | pairNotMember :: (Ord a, Ord b) => (a, b) -> Bimap a b -> Bool | | | lookup :: (Ord a, Ord b, Monad m) => Either a b -> Bimap a b -> m (a, b) | | | lookupL :: (Ord a, Ord b, Monad m) => a -> Bimap a b -> m b | | | lookupR :: (Ord a, Ord b, Monad m) => b -> Bimap a b -> m a | | | (!) :: (Ord a, Ord b) => Bimap a b -> Either a b -> (a, b) | | | (!<) :: (Ord a, Ord b) => Bimap a b -> a -> b | | | (!>) :: (Ord a, Ord b) => Bimap a b -> b -> a | | | empty :: Bimap a b | | | singleton :: (Ord a, Ord b) => (a, b) -> Bimap a b | | | insert :: (Ord a, Ord b) => (a, b) -> Bimap a b -> Bimap a b | | | delete :: (Ord a, Ord b) => Either a b -> Bimap a b -> Bimap a b | | | deleteL :: (Ord a, Ord b) => a -> Bimap a b -> Bimap a b | | | deleteR :: (Ord a, Ord b) => b -> Bimap a b -> Bimap a b | | | fromList :: (Ord a, Ord b) => [(a, b)] -> Bimap a b | | | toList :: Bimap a b -> [(a, b)] | | | assocs :: Bimap a b -> [(a, b)] | | | fold :: ((a, b) -> c -> c) -> c -> Bimap a b -> c | | | valid :: (Ord a, Ord b) => Bimap a b -> Bool | | | twist :: (Ord a, Ord b) => Bimap a b -> Bimap b a |
|
|
|
| Bimap type
|
|
| data Bimap a b |
| A bidirectional map between values of types a and b.
| Instances | |
|
|
| Query
|
|
| null :: Bimap a b -> Bool |
| Is the bimap empty?
|
|
| size :: Bimap a b -> Int |
| The number of elements in the bimap.
|
|
| member :: (Ord a, Ord b) => Either a b -> Bimap a b -> Bool |
| Is the specified value a member of the bimap?
|
|
| memberL :: (Ord a, Ord b) => a -> Bimap a b -> Bool |
| A version of member specialized to the left key.
|
|
| memberR :: (Ord a, Ord b) => b -> Bimap a b -> Bool |
| A version of member specialized to the right key.
|
|
| notMember :: (Ord a, Ord b) => Either a b -> Bimap a b -> Bool |
| Is the specified value not a member of the bimap?
|
|
| notMemberL :: (Ord a, Ord b) => a -> Bimap a b -> Bool |
| A version of notMember specialized to the left key.
|
|
| notMemberR :: (Ord a, Ord b) => b -> Bimap a b -> Bool |
| A version of notMember specialized to the right key.
|
|
| pairMember :: (Ord a, Ord b) => (a, b) -> Bimap a b -> Bool |
| Are the two values associated with each other in the bimap?
|
|
| pairNotMember :: (Ord a, Ord b) => (a, b) -> Bimap a b -> Bool |
| Are the two values not in the bimap, or not associated with
each other? (Complement of pairMember.)
|
|
| lookup :: (Ord a, Ord b, Monad m) => Either a b -> Bimap a b -> m (a, b) |
Lookup the twin of a value in the bimap, returning both
associated values as a pair.
This function will return the result in the monad, or fail if
the value isn't in the bimap.
|
|
| lookupL :: (Ord a, Ord b, Monad m) => a -> Bimap a b -> m b |
| A version of lookup that is specialized to the left key,
and returns only the right key.
|
|
| lookupR :: (Ord a, Ord b, Monad m) => b -> Bimap a b -> m a |
| A version of lookup that is specialized to the right key,
and returns only the left key.
|
|
| (!) :: (Ord a, Ord b) => Bimap a b -> Either a b -> (a, b) |
| Find the pair corresponding to a given value. Calls error
when the value is not in the bimap.
|
|
| (!<) :: (Ord a, Ord b) => Bimap a b -> a -> b |
| A version of '(!)' that is specialized to the left key,
and returns only the right key.
|
|
| (!>) :: (Ord a, Ord b) => Bimap a b -> b -> a |
| A version of '(!)' that is specialized to the right key,
and returns only the left key.
|
|
| Construction
|
|
| empty :: Bimap a b |
| The empty bimap.
|
|
| singleton :: (Ord a, Ord b) => (a, b) -> Bimap a b |
| A bimap with a single element.
|
|
| Update
|
|
| insert :: (Ord a, Ord b) => (a, b) -> Bimap a b -> Bimap a b |
| Insert a pair of values into the bimap, associating them.
If either of the values is already in the bimap, any overlapping
bindings are deleted.
|
|
| delete :: (Ord a, Ord b) => Either a b -> Bimap a b -> Bimap a b |
| Delete a value and its twin from a bimap.
When the value is not a member of the bimap, the original bimap is
returned.
|
|
| deleteL :: (Ord a, Ord b) => a -> Bimap a b -> Bimap a b |
| A version of delete specialized to the left key.
|
|
| deleteR :: (Ord a, Ord b) => b -> Bimap a b -> Bimap a b |
| A version of delete specialized to the right key.
|
|
| Conversion/traversal
|
|
| fromList :: (Ord a, Ord b) => [(a, b)] -> Bimap a b |
| Build a map from a list of pairs. If there are any overlapping
pairs in the list, the later ones will override the earlier ones.
|
|
| toList :: Bimap a b -> [(a, b)] |
| Convert to a list of associated pairs.
|
|
| assocs :: Bimap a b -> [(a, b)] |
| Return all associated pairs in the bimap, with the left-hand
values in ascending order.
|
|
| fold :: ((a, b) -> c -> c) -> c -> Bimap a b -> c |
| Fold the association pairs in the map, such that
fold f z == foldr f z . assocs.
|
|
| Miscellaneous
|
|
| valid :: (Ord a, Ord b) => Bimap a b -> Bool |
| Test if the internal bimap structure is valid.
|
|
| twist :: (Ord a, Ord b) => Bimap a b -> Bimap b a |
| Reverse the positions of the two element types in the bimap.
|
|
| Produced by Haddock version 0.8 |