on 63407dc help sign in
52 lines 1.4 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
32instance Ord k => IsMap (Map k) where
33 type Key (Map k) = k
35 mapEmpty = Map.empty
36 mapAlterF = Map.alterF
37 mapLookup = Map.lookup
38 mapInsert = Map.insert
39 mapDelete = Map.delete
40 mapUnion = Map.union
41 mapNull = Map.null
43instance IsMap IntMap.IntMap where
44 type Key IntMap.IntMap = Int
46 mapEmpty = IntMap.empty
47 mapAlterF = IntMap.alterF
48 mapLookup = IntMap.lookup
49 mapInsert = IntMap.insert
50 mapDelete = IntMap.delete
51 mapUnion = IntMap.union
52 mapNull = IntMap.null