Copyright | (c) Adam Wagner 2017 |
---|---|
Safe Haskell | None |
Language | Haskell2010 |
Identifiers for Hashable values.
Example usage:
>>>
xs = fromList ["foo", "bar", "baz", "foo"]
>>>
lookupId xs "baz"
Just 2>>>
lookupKey xs 2
Just "baz"
- data Identifiers i a
- empty :: Identifiers i a
- fromList :: (Integral i, Hashable a, Eq a) => [a] -> Identifiers i a
- combine :: (Integral i, Hashable a, Eq a) => Identifiers i a -> Identifiers i a -> (Identifiers i a, Map i i)
- insert :: (Integral i, Hashable a, Eq a) => Identifiers i a -> a -> Identifiers i a
- insertMany :: (Integral i, Hashable a, Eq a) => Identifiers i a -> [a] -> Identifiers i a
- size :: Identifiers i a -> Int
- toList :: Identifiers i a -> [a]
- lookupId :: (Hashable a, Eq a) => Identifiers i a -> a -> Maybe i
- lookupKey :: Integral i => Identifiers i a -> i -> Maybe a
- lookupKeys :: Integral i => Identifiers i a -> [i] -> [a]
- unsafeLookupId :: (Hashable a, Eq a) => Identifiers i a -> a -> i
- unsafeLookupKey :: Integral i => Identifiers i a -> i -> a
- (!) :: Integral i => Identifiers i a -> i -> a
- prop_hasId :: String -> Bool
- prop_stableId :: String -> Bool
- prop_keyRetrieval :: [String] -> Bool
- prop_keyRetrievalUnsafe :: [String] -> Bool
- prop_idempotent :: String -> Bool
- prop_stableCombine :: [String] -> [String] -> Bool
- prop_properMigration :: [String] -> [String] -> Bool
Documentation
data Identifiers i a Source #
(Eq i, Eq a) => Eq (Identifiers i a) Source # | |
Show a => Show (Identifiers i a) Source # | |
(Binary i, Eq a, Hashable a, Binary a) => Binary (Identifiers i a) Source # | |
(Serialize i, Eq a, Hashable a, Serialize a) => Serialize (Identifiers i a) Source # | |
(NFData i, NFData a) => NFData (Identifiers i a) Source # | |
Construction
empty :: Identifiers i a Source #
The empty Identifiers
fromList :: (Integral i, Hashable a, Eq a) => [a] -> Identifiers i a Source #
New Identifiers from list
combine :: (Integral i, Hashable a, Eq a) => Identifiers i a -> Identifiers i a -> (Identifiers i a, Map i i) Source #
Combine two identifier sets into one. Because the ids will change while combining two sets, a map is also returned that identifies the new location of old ids for the second set passed in.
Insertion
insert :: (Integral i, Hashable a, Eq a) => Identifiers i a -> a -> Identifiers i a Source #
Insert item into set (given it a new id)
insertMany :: (Integral i, Hashable a, Eq a) => Identifiers i a -> [a] -> Identifiers i a Source #
Insert many items into set
Info
size :: Identifiers i a -> Int Source #
Number of items in Identifiers value
Extraction
toList :: Identifiers i a -> [a] Source #
New List from Identifiers
Lookups
lookupKeys :: Integral i => Identifiers i a -> [i] -> [a] Source #
Given many ids, return many keys
unsafeLookupId :: (Hashable a, Eq a) => Identifiers i a -> a -> i Source #
Find numeric id for given value. Will error when the value is not a member of the Identifiers map.
unsafeLookupKey :: Integral i => Identifiers i a -> i -> a Source #
Find id for given value. Will error when the id has no associated value.
(!) :: Integral i => Identifiers i a -> i -> a Source #
Infix version of unsafeLookupKey
Properties
prop_hasId :: String -> Bool Source #
Items inserted are given ids
prop_stableId :: String -> Bool Source #
Inserted items have stable ids
prop_keyRetrieval :: [String] -> Bool Source #
Given id can be used to fetch inserted item
prop_keyRetrievalUnsafe :: [String] -> Bool Source #
Given id can be used to fetch inserted item
prop_idempotent :: String -> Bool Source #
Inserting something more than once does not change the set