insert-ordered-containers-0.2.1.0: Associative containers retating insertion order for traversals.

Safe Haskell | Trustworthy
Language | Haskell2010

Data.HashMap.Strict.InsOrd

Contents

- Construction
- Basic interface
- Combine
- Transformations
  - Unordered
- Difference and intersection
- Folds
  - Unordered
- Filter
- Conversions
- Lenses
- Debugging

Description

`InsOrdHashMap` is like `HashMap`, but it folds and traverses in insertion order.

This module interface mimics Data.HashMap.Strict, with some additions.

Synopsis

- data InsOrdHashMap k v
- empty :: InsOrdHashMap k v
- singleton :: Hashable k => k -> v -> InsOrdHashMap k v
- null :: InsOrdHashMap k v -> Bool
- size :: InsOrdHashMap k v -> Int
- member :: (Eq k, Hashable k) => k -> InsOrdHashMap k a -> Bool
- lookup :: (Eq k, Hashable k) => k -> InsOrdHashMap k v -> Maybe v
- lookupDefault :: (Eq k, Hashable k) => v -> k -> InsOrdHashMap k v -> v
- insert :: (Eq k, Hashable k) => k -> v -> InsOrdHashMap k v -> InsOrdHashMap k v
- insertWith :: (Eq k, Hashable k) => (v -> v -> v) -> k -> v -> InsOrdHashMap k v -> InsOrdHashMap k v
- delete :: (Eq k, Hashable k) => k -> InsOrdHashMap k v -> InsOrdHashMap k v
- adjust :: (Eq k, Hashable k) => (v -> v) -> k -> InsOrdHashMap k v -> InsOrdHashMap k v
- update :: (Eq k, Hashable k) => (a -> Maybe a) -> k -> InsOrdHashMap k a -> InsOrdHashMap k a
- alter :: (Eq k, Hashable k) => (Maybe v -> Maybe v) -> k -> InsOrdHashMap k v -> InsOrdHashMap k v
- union :: (Eq k, Hashable k) => InsOrdHashMap k v -> InsOrdHashMap k v -> InsOrdHashMap k v
- unionWith :: (Eq k, Hashable k) => (v -> v -> v) -> InsOrdHashMap k v -> InsOrdHashMap k v -> InsOrdHashMap k v
- unionWithKey :: (Eq k, Hashable k) => (k -> v -> v -> v) -> InsOrdHashMap k v -> InsOrdHashMap k v -> InsOrdHashMap k v
- unions :: (Eq k, Hashable k, Foldable f) => f (InsOrdHashMap k v) -> InsOrdHashMap k v
- map :: (v1 -> v2) -> InsOrdHashMap k v1 -> InsOrdHashMap k v2
- mapKeys :: (Eq k', Hashable k') => (k -> k') -> InsOrdHashMap k v -> InsOrdHashMap k' v
- traverseKeys :: (Eq k', Hashable k', Applicative f) => (k -> f k') -> InsOrdHashMap k v -> f (InsOrdHashMap k' v)
- mapWithKey :: (k -> v1 -> v2) -> InsOrdHashMap k v1 -> InsOrdHashMap k v2
- traverseWithKey :: Applicative f => (k -> a -> f b) -> InsOrdHashMap k a -> f (InsOrdHashMap k b)
- unorderedTraverse :: Applicative f => (a -> f b) -> InsOrdHashMap k a -> f (InsOrdHashMap k b)
- unorderedTraverseWithKey :: Applicative f => (k -> a -> f b) -> InsOrdHashMap k a -> f (InsOrdHashMap k b)
- difference :: (Eq k, Hashable k) => InsOrdHashMap k v -> InsOrdHashMap k w -> InsOrdHashMap k v
- intersection :: (Eq k, Hashable k) => InsOrdHashMap k v -> InsOrdHashMap k w -> InsOrdHashMap k v
- intersectionWith :: (Eq k, Hashable k) => (v1 -> v2 -> v3) -> InsOrdHashMap k v1 -> InsOrdHashMap k v2 -> InsOrdHashMap k v3
- intersectionWithKey :: (Eq k, Hashable k) => (k -> v1 -> v2 -> v3) -> InsOrdHashMap k v1 -> InsOrdHashMap k v2 -> InsOrdHashMap k v3
- foldl' :: (a -> v -> a) -> a -> InsOrdHashMap k v -> a
- foldlWithKey' :: (a -> k -> v -> a) -> a -> InsOrdHashMap k v -> a
- foldr :: (v -> a -> a) -> a -> InsOrdHashMap k v -> a
- foldrWithKey :: (k -> v -> a -> a) -> a -> InsOrdHashMap k v -> a
- foldMapWithKey :: Monoid m => (k -> a -> m) -> InsOrdHashMap k a -> m
- unorderedFoldMap :: Monoid m => (a -> m) -> InsOrdHashMap k a -> m
- unorderedFoldMapWithKey :: Monoid m => (k -> a -> m) -> InsOrdHashMap k a -> m
- filter :: (v -> Bool) -> InsOrdHashMap k v -> InsOrdHashMap k v
- filterWithKey :: (k -> v -> Bool) -> InsOrdHashMap k v -> InsOrdHashMap k v
- mapMaybe :: (v1 -> Maybe v2) -> InsOrdHashMap k v1 -> InsOrdHashMap k v2
- mapMaybeWithKey :: (k -> v1 -> Maybe v2) -> InsOrdHashMap k v1 -> InsOrdHashMap k v2
- keys :: InsOrdHashMap k v -> [k]
- elems :: InsOrdHashMap k v -> [v]
- toList :: InsOrdHashMap k v -> [(k, v)]
- toRevList :: InsOrdHashMap k v -> [(k, v)]
- fromList :: forall k v. (Eq k, Hashable k) => [(k, v)] -> InsOrdHashMap k v
- toHashMap :: InsOrdHashMap k v -> HashMap k v
- fromHashMap :: HashMap k v -> InsOrdHashMap k v
- hashMap :: Iso (InsOrdHashMap k a) (InsOrdHashMap k b) (HashMap k a) (HashMap k b)
- unorderedTraversal :: Traversal (InsOrdHashMap k a) (InsOrdHashMap k b) a b
- valid :: InsOrdHashMap k v -> Bool

# Documentation

data InsOrdHashMap k v #

`HashMap` which tries it's best to remember insertion order of elements.

Instances

(Eq k, Hashable k) => FunctorWithIndex k (InsOrdHashMap k) # |
Methods imap :: (k -> a -> b) -> InsOrdHashMap k a -> InsOrdHashMap k b # imapped :: (Indexable k p, Settable f) => p a (f b) -> InsOrdHashMap k a -> f (InsOrdHashMap k b) #
(Eq k, Hashable k) => FoldableWithIndex k (InsOrdHashMap k) # |
Methods ifoldMap :: Monoid m => (k -> a -> m) -> InsOrdHashMap k a -> m # ifolded :: (Indexable k p, Contravariant f, Applicative f) => p a (f a) -> InsOrdHashMap k a -> f (InsOrdHashMap k a) # ifoldr :: (k -> a -> b -> b) -> b -> InsOrdHashMap k a -> b # ifoldl :: (k -> b -> a -> b) -> b -> InsOrdHashMap k a -> b # ifoldr' :: (k -> a -> b -> b) -> b -> InsOrdHashMap k a -> b # ifoldl' :: (k -> b -> a -> b) -> b -> InsOrdHashMap k a -> b #
(Eq k, Hashable k) => TraversableWithIndex k (InsOrdHashMap k) # |
Methods itraverse :: Applicative f => (k -> a -> f b) -> InsOrdHashMap k a -> f (InsOrdHashMap k b) # itraversed :: (Indexable k p, Applicative f) => p a (f b) -> InsOrdHashMap k a -> f (InsOrdHashMap k b) #
Functor (InsOrdHashMap k) # |
Methods fmap :: (a -> b) -> InsOrdHashMap k a -> InsOrdHashMap k b # (<$) :: a -> InsOrdHashMap k b -> InsOrdHashMap k a #
Foldable (InsOrdHashMap k) # |
Methods fold :: Monoid m => InsOrdHashMap k m -> m # foldMap :: Monoid m => (a -> m) -> InsOrdHashMap k a -> m # foldr :: (a -> b -> b) -> b -> InsOrdHashMap k a -> b # foldr' :: (a -> b -> b) -> b -> InsOrdHashMap k a -> b # foldl :: (b -> a -> b) -> b -> InsOrdHashMap k a -> b # foldl' :: (b -> a -> b) -> b -> InsOrdHashMap k a -> b # foldr1 :: (a -> a -> a) -> InsOrdHashMap k a -> a # foldl1 :: (a -> a -> a) -> InsOrdHashMap k a -> a # toList :: InsOrdHashMap k a -> [a] # null :: InsOrdHashMap k a -> Bool # length :: InsOrdHashMap k a -> Int # elem :: Eq a => a -> InsOrdHashMap k a -> Bool # maximum :: Ord a => InsOrdHashMap k a -> a # minimum :: Ord a => InsOrdHashMap k a -> a # sum :: Num a => InsOrdHashMap k a -> a # product :: Num a => InsOrdHashMap k a -> a #
Traversable (InsOrdHashMap k) # |
Methods traverse :: Applicative f => (a -> f b) -> InsOrdHashMap k a -> f (InsOrdHashMap k b) # sequenceA :: Applicative f => InsOrdHashMap k (f a) -> f (InsOrdHashMap k a) # mapM :: Monad m => (a -> m b) -> InsOrdHashMap k a -> m (InsOrdHashMap k b) # sequence :: Monad m => InsOrdHashMap k (m a) -> m (InsOrdHashMap k a) #
ToJSONKey k => ToJSON1 (InsOrdHashMap k) # |
Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> InsOrdHashMap k a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [InsOrdHashMap k a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> InsOrdHashMap k a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [InsOrdHashMap k a] -> Encoding #
(Eq k, Hashable k, FromJSONKey k) => FromJSON1 (InsOrdHashMap k) # |
Methods liftParseJSON :: (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser (InsOrdHashMap k a) # liftParseJSONList :: (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser [InsOrdHashMap k a] #
(Eq k, Hashable k) => Apply (InsOrdHashMap k) # |
Methods (<.>) :: InsOrdHashMap k (a -> b) -> InsOrdHashMap k a -> InsOrdHashMap k b # (.>) :: InsOrdHashMap k a -> InsOrdHashMap k b -> InsOrdHashMap k b # (<.) :: InsOrdHashMap k a -> InsOrdHashMap k b -> InsOrdHashMap k a #
(Eq k, Hashable k) => Bind (InsOrdHashMap k) # |
Methods (>>-) :: InsOrdHashMap k a -> (a -> InsOrdHashMap k b) -> InsOrdHashMap k b # join :: InsOrdHashMap k (InsOrdHashMap k a) -> InsOrdHashMap k a #
(Eq k, Hashable k) => IsList (InsOrdHashMap k v) # |
Associated Types type Item (InsOrdHashMap k v) :: * # Methods fromList :: [Item (InsOrdHashMap k v)] -> InsOrdHashMap k v # fromListN :: Int -> [Item (InsOrdHashMap k v)] -> InsOrdHashMap k v # toList :: InsOrdHashMap k v -> [Item (InsOrdHashMap k v)] #
(Eq k, Eq v) => Eq (InsOrdHashMap k v) # |
Methods (==) :: InsOrdHashMap k v -> InsOrdHashMap k v -> Bool # (/=) :: InsOrdHashMap k v -> InsOrdHashMap k v -> Bool #
(Hashable k, Eq k, Data v, Data k) => Data (InsOrdHashMap k v) # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> InsOrdHashMap k v -> c (InsOrdHashMap k v) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (InsOrdHashMap k v) # toConstr :: InsOrdHashMap k v -> Constr # dataTypeOf :: InsOrdHashMap k v -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (InsOrdHashMap k v)) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (InsOrdHashMap k v)) # gmapT :: (forall b. Data b => b -> b) -> InsOrdHashMap k v -> InsOrdHashMap k v # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> InsOrdHashMap k v -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> InsOrdHashMap k v -> r # gmapQ :: (forall d. Data d => d -> u) -> InsOrdHashMap k v -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> InsOrdHashMap k v -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> InsOrdHashMap k v -> m (InsOrdHashMap k v) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> InsOrdHashMap k v -> m (InsOrdHashMap k v) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> InsOrdHashMap k v -> m (InsOrdHashMap k v) #
(Eq k, Hashable k, Read k, Read v) => Read (InsOrdHashMap k v) # |
Methods readsPrec :: Int -> ReadS (InsOrdHashMap k v) # readList :: ReadS [InsOrdHashMap k v] # readPrec :: ReadPrec (InsOrdHashMap k v) # readListPrec :: ReadPrec [InsOrdHashMap k v] #
(Show k, Show v) => Show (InsOrdHashMap k v) # |
Methods showsPrec :: Int -> InsOrdHashMap k v -> ShowS # show :: InsOrdHashMap k v -> String # showList :: [InsOrdHashMap k v] -> ShowS #
(Eq k, Hashable k) => Semigroup (InsOrdHashMap k v) # |
Methods (<>) :: InsOrdHashMap k v -> InsOrdHashMap k v -> InsOrdHashMap k v # sconcat :: NonEmpty (InsOrdHashMap k v) -> InsOrdHashMap k v # stimes :: Integral b => b -> InsOrdHashMap k v -> InsOrdHashMap k v #
(Eq k, Hashable k) => Monoid (InsOrdHashMap k v) # |
Methods mempty :: InsOrdHashMap k v # mappend :: InsOrdHashMap k v -> InsOrdHashMap k v -> InsOrdHashMap k v # mconcat :: [InsOrdHashMap k v] -> InsOrdHashMap k v #
(Hashable k, Hashable v) => Hashable (InsOrdHashMap k v) # | `hashWithSalt salt . toHashMap = hashWithSalt salt`.
Methods hashWithSalt :: Int -> InsOrdHashMap k v -> Int # hash :: InsOrdHashMap k v -> Int #
(ToJSONKey k, ToJSON v) => ToJSON (InsOrdHashMap k v) # |
Methods toJSON :: InsOrdHashMap k v -> Value # toEncoding :: InsOrdHashMap k v -> Encoding # toJSONList :: [InsOrdHashMap k v] -> Value # toEncodingList :: [InsOrdHashMap k v] -> Encoding #
(Eq k, Hashable k, FromJSONKey k, FromJSON v) => FromJSON (InsOrdHashMap k v) # |
Methods parseJSON :: Value -> Parser (InsOrdHashMap k v) # parseJSONList :: Value -> Parser [InsOrdHashMap k v] #
(Eq k, Hashable k) => Ixed (InsOrdHashMap k v) # |
Methods ix :: Index (InsOrdHashMap k v) -> Traversal' (InsOrdHashMap k v) (IxValue (InsOrdHashMap k v)) #
(Eq k, Hashable k) => At (InsOrdHashMap k a) # |
Methods at :: Index (InsOrdHashMap k a) -> Lens' (InsOrdHashMap k a) (Maybe (IxValue (InsOrdHashMap k a))) #
type Item (InsOrdHashMap k v) # |
type Item (InsOrdHashMap k v) = (k, v)
type Index (InsOrdHashMap k v) # |
type Index (InsOrdHashMap k v) = k
type IxValue (InsOrdHashMap k v) # |
type IxValue (InsOrdHashMap k v) = v

# Construction

empty :: InsOrdHashMap k v #

singleton :: Hashable k => k -> v -> InsOrdHashMap k v #

# Basic interface

null :: InsOrdHashMap k v -> Bool #

size :: InsOrdHashMap k v -> Int #

member :: (Eq k, Hashable k) => k -> InsOrdHashMap k a -> Bool #

lookup :: (Eq k, Hashable k) => k -> InsOrdHashMap k v -> Maybe v #

lookupDefault #

Arguments

:: (Eq k, Hashable k) |
=> v | Default value to return.
-> k |
-> InsOrdHashMap k v |
-> v |

insert :: (Eq k, Hashable k) => k -> v -> InsOrdHashMap k v -> InsOrdHashMap k v #

insertWith :: (Eq k, Hashable k) => (v -> v -> v) -> k -> v -> InsOrdHashMap k v -> InsOrdHashMap k v #

delete :: (Eq k, Hashable k) => k -> InsOrdHashMap k v -> InsOrdHashMap k v #

adjust :: (Eq k, Hashable k) => (v -> v) -> k -> InsOrdHashMap k v -> InsOrdHashMap k v #

update :: (Eq k, Hashable k) => (a -> Maybe a) -> k -> InsOrdHashMap k a -> InsOrdHashMap k a #

alter :: (Eq k, Hashable k) => (Maybe v -> Maybe v) -> k -> InsOrdHashMap k v -> InsOrdHashMap k v #

# Combine

union :: (Eq k, Hashable k) => InsOrdHashMap k v -> InsOrdHashMap k v -> InsOrdHashMap k v #

unionWith :: (Eq k, Hashable k) => (v -> v -> v) -> InsOrdHashMap k v -> InsOrdHashMap k v -> InsOrdHashMap k v #

The union of two maps. If a key occurs in both maps, the provided function (first argument) will be used to compute the result.

Ordered traversal will go thru keys in the first map first.

unionWithKey :: (Eq k, Hashable k) => (k -> v -> v -> v) -> InsOrdHashMap k v -> InsOrdHashMap k v -> InsOrdHashMap k v #

unions :: (Eq k, Hashable k, Foldable f) => f (InsOrdHashMap k v) -> InsOrdHashMap k v #

# Transformations

map :: (v1 -> v2) -> InsOrdHashMap k v1 -> InsOrdHashMap k v2 #

mapKeys :: (Eq k', Hashable k') => (k -> k') -> InsOrdHashMap k v -> InsOrdHashMap k' v #

Order preserving mapping of keys.

traverseKeys :: (Eq k', Hashable k', Applicative f) => (k -> f k') -> InsOrdHashMap k v -> f (InsOrdHashMap k' v) #

mapWithKey :: (k -> v1 -> v2) -> InsOrdHashMap k v1 -> InsOrdHashMap k v2 #

traverseWithKey :: Applicative f => (k -> a -> f b) -> InsOrdHashMap k a -> f (InsOrdHashMap k b) #

## Unordered

unorderedTraverse :: Applicative f => (a -> f b) -> InsOrdHashMap k a -> f (InsOrdHashMap k b) #

More efficient than `traverse`, when traversing in insertion order is not important.

unorderedTraverseWithKey :: Applicative f => (k -> a -> f b) -> InsOrdHashMap k a -> f (InsOrdHashMap k b) #

More efficient than `traverseWithKey`, when traversing in insertion order is not important.

# Difference and intersection

difference :: (Eq k, Hashable k) => InsOrdHashMap k v -> InsOrdHashMap k w -> InsOrdHashMap k v #

intersection :: (Eq k, Hashable k) => InsOrdHashMap k v -> InsOrdHashMap k w -> InsOrdHashMap k v #

intersectionWith :: (Eq k, Hashable k) => (v1 -> v2 -> v3) -> InsOrdHashMap k v1 -> InsOrdHashMap k v2 -> InsOrdHashMap k v3 #

intersectionWithKey :: (Eq k, Hashable k) => (k -> v1 -> v2 -> v3) -> InsOrdHashMap k v1 -> InsOrdHashMap k v2 -> InsOrdHashMap k v3 #

# Folds

foldl' :: (a -> v -> a) -> a -> InsOrdHashMap k v -> a #

foldlWithKey' :: (a -> k -> v -> a) -> a -> InsOrdHashMap k v -> a #

foldr :: (v -> a -> a) -> a -> InsOrdHashMap k v -> a #

foldrWithKey :: (k -> v -> a -> a) -> a -> InsOrdHashMap k v -> a #

foldMapWithKey :: Monoid m => (k -> a -> m) -> InsOrdHashMap k a -> m #

## Unordered

unorderedFoldMap :: Monoid m => (a -> m) -> InsOrdHashMap k a -> m #

More efficient than `foldMap`, when folding in insertion order is not important.

unorderedFoldMapWithKey :: Monoid m => (k -> a -> m) -> InsOrdHashMap k a -> m #

More efficient than `foldMapWithKey`, when folding in insertion order is not important.

# Filter

filter :: (v -> Bool) -> InsOrdHashMap k v -> InsOrdHashMap k v #

filterWithKey :: (k -> v -> Bool) -> InsOrdHashMap k v -> InsOrdHashMap k v #

mapMaybe :: (v1 -> Maybe v2) -> InsOrdHashMap k v1 -> InsOrdHashMap k v2 #

mapMaybeWithKey :: (k -> v1 -> Maybe v2) -> InsOrdHashMap k v1 -> InsOrdHashMap k v2 #

# Conversions

keys :: InsOrdHashMap k v -> [k] #

elems :: InsOrdHashMap k v -> [v] #

toList :: InsOrdHashMap k v -> [(k, v)] #

toRevList :: InsOrdHashMap k v -> [(k, v)] #

fromList :: forall k v. (Eq k, Hashable k) => [(k, v)] -> InsOrdHashMap k v #

toHashMap :: InsOrdHashMap k v -> HashMap k v #

fromHashMap :: HashMap k v -> InsOrdHashMap k v #

# Lenses

hashMap :: Iso (InsOrdHashMap k a) (InsOrdHashMap k b) (HashMap k a) (HashMap k b) #

This is a slight lie, as roundtrip doesn't preserve ordering.

unorderedTraversal :: Traversal (InsOrdHashMap k a) (InsOrdHashMap k b) a b #

# Debugging

valid :: InsOrdHashMap k v -> Bool #

Test if the internal map structure is valid.