on defafa6 help sign in
56 lines 1.5 kB history raw
1-- |
2-- Module : Streamly.Internal.Data.IsMap
3-- Copyright : (c) 2022 Composewell Technologies
4-- License : BSD-3-Clause
5-- Maintainer : streamly@composewell.com
6-- Stability : experimental
7-- Portability : GHC
9module Streamly.Internal.Data.IsMap (IsMap(..)) where
11import Data.Kind (Type)
12import Data.Map.Strict (Map)
14import qualified Data.IntMap.Strict as IntMap
15import qualified Data.Map.Strict as Map
17-- XXX Try unpacked-containers
19class IsMap f where
20 type Key f :: Type
22 mapEmpty :: f a
23 mapAlterF :: Functor g =>
24 (Maybe a -> g (Maybe a)) -> Key f -> f a -> g (f a)
25 -- These can be implemented in terms of alterF itself
26 mapLookup :: Key f -> f a -> Maybe a
27 mapInsert :: Key f -> a -> f a -> f a
28 mapDelete :: Key f -> f a -> f a
29 mapUnion :: f a -> f a -> f a
30 mapNull :: f a -> Bool
31 mapTraverseWithKey ::
32 Applicative t => (Key f -> a -> t b) -> f a -> t (f b)
34instance Ord k => IsMap (Map k) where
35 type Key (Map k) = k
37 mapEmpty = Map.empty
38 mapAlterF = Map.alterF
39 mapLookup = Map.lookup
40 mapInsert = Map.insert
41 mapDelete = Map.delete
42 mapUnion = Map.union
43 mapNull = Map.null
44 mapTraverseWithKey = Map.traverseWithKey
46instance IsMap IntMap.IntMap where
47 type Key IntMap.IntMap = Int
49 mapEmpty = IntMap.empty
50 mapAlterF = IntMap.alterF
51 mapLookup = IntMap.lookup
52 mapInsert = IntMap.insert
53 mapDelete = IntMap.delete
54 mapUnion = IntMap.union
55 mapNull = IntMap.null
56 mapTraverseWithKey = IntMap.traverseWithKey