summaryrefslogtreecommitdiff
path: root/IntMapClass.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2014-08-13 18:35:18 -0400
committerjoe <joe@jerkface.net>2014-08-13 18:35:18 -0400
commitc72a0a292d3b3e5b0c6d0c5cf395e658556eb4a2 (patch)
tree850910b0e9b39e9b157b74bc9a41c05baa40d547 /IntMapClass.hs
parent78a6247d65684cb9c0690b7f9eb6e0ceb0d433d9 (diff)
more IMap k a
Diffstat (limited to 'IntMapClass.hs')
-rw-r--r--IntMapClass.hs43
1 files changed, 43 insertions, 0 deletions
diff --git a/IntMapClass.hs b/IntMapClass.hs
index ce544f9..77ce16b 100644
--- a/IntMapClass.hs
+++ b/IntMapClass.hs
@@ -89,6 +89,7 @@ lookup = adapt_k_m (IntMap.lookup)
89findWithDefault :: Coercible k Int => x -> k -> IMap k x -> x 89findWithDefault :: Coercible k Int => x -> k -> IMap k x -> x
90findWithDefault a = adapt_k_m (IntMap.findWithDefault a) 90findWithDefault a = adapt_k_m (IntMap.findWithDefault a)
91 91
92-- FIXME: fmap (first coerce) probably incurs cost
92lookupLT :: ( Coercible Int k, Coercible k Int ) => k -> IMap k a -> Maybe (k, a) 93lookupLT :: ( Coercible Int k, Coercible k Int ) => k -> IMap k a -> Maybe (k, a)
93lookupLT k m = fmap (first coerce) $ adapt_k_m (IntMap.lookupLT) k m 94lookupLT k m = fmap (first coerce) $ adapt_k_m (IntMap.lookupLT) k m
94lookupGT :: ( Coercible Int k, Coercible k Int ) => k -> IMap k a -> Maybe (k, a) 95lookupGT :: ( Coercible Int k, Coercible k Int ) => k -> IMap k a -> Maybe (k, a)
@@ -194,6 +195,7 @@ map f = IMap . adapt_m (IntMap.map f)
194mapWithKey :: Coercible Int k => (k -> a -> b) -> IMap k a -> IMap k b 195mapWithKey :: Coercible Int k => (k -> a -> b) -> IMap k a -> IMap k b
195mapWithKey f = IMap . adapt_m (IntMap.mapWithKey $ f . coerce) 196mapWithKey f = IMap . adapt_m (IntMap.mapWithKey $ f . coerce)
196 197
198-- FIXME: fmap IMap ?
197traverseWithKey :: 199traverseWithKey ::
198 (Applicative f, Coercible Int k) => 200 (Applicative f, Coercible Int k) =>
199 (k -> a -> f b) -> IMap k a -> f (IMap k b) 201 (k -> a -> f b) -> IMap k a -> f (IMap k b)
@@ -283,4 +285,45 @@ fromListWithKey :: ( Coercible Int k
283 (k -> a -> a -> a) -> [(k, a)] -> IMap k a 285 (k -> a -> a -> a) -> [(k, a)] -> IMap k a
284fromListWithKey f = IMap . IntMap.fromListWithKey (f . coerce) . coerce 286fromListWithKey f = IMap . IntMap.fromListWithKey (f . coerce) . coerce
285 287
288toAscList :: Coercible [(Int,a)] [(k,a)] => IMap k a -> [(k,a)]
289toAscList (IMap m) = coerce $ IntMap.toAscList m
290
291toDescList :: Coercible [(Int,a)] [(k,a)] => IMap k a -> [(k,a)]
292toDescList (IMap m) = coerce $ IntMap.toDescList m
293
294fromAscList :: Coercible [(k,a)] [(Int,a)] => [(k, a)] -> IMap k a
295fromAscList = IMap . IntMap.fromAscList . coerce
296
297fromAscListWith ::
298 Coercible [(k,a)] [(Int, a)] =>
299 (a -> a -> a) -> [(k,a)] -> IMap k a
300fromAscListWith f = IMap . IntMap.fromAscListWith f . coerce
301
302fromAscListWithKey ::
303 (Coercible Int k, Coercible [(k,a)] [(Int, a)]) =>
304 (k -> a -> a -> a) -> [(k,a)] -> IMap k a
305fromAscListWithKey f = IMap . IntMap.fromAscListWithKey (f . coerce) . coerce
306
307fromDistinctAscList :: Coercible [(k,a)] [(Int,a)] => [(k, a)] -> IMap k a
308fromDistinctAscList = IMap . IntMap.fromDistinctAscList . coerce
309
310filter :: (a -> Bool) -> IMap k a -> IMap k a
311filter f = IMap . adapt_m (IntMap.filter f)
312
313filterWithKey :: Coercible Int k => (k -> a -> Bool) -> IMap k a -> IMap k a
314filterWithKey f = IMap . adapt_m (IntMap.filterWithKey $ f . coerce)
315
316partition :: Coercible (IntMap a,IntMap a) (IMap k a,IMap k a)
317 => (a -> Bool) -> IMap k a -> (IMap k a, IMap k a)
318partition f m = coerce $ IntMap.partition f (intmap m)
319
320
321partitionWithKey :: ( Coercible Int k
322 , Coercible (IntMap a,IntMap a) (IMap k a,IMap k a) )
323 => (k -> a -> Bool) -> IMap k a -> (IMap k a, IMap k a)
324partitionWithKey f m = coerce $ IntMap.partitionWithKey (f . coerce) (intmap m)
325
326mapMaybe :: (a -> Maybe b) -> IMap k a -> IMap k b
327mapMaybe f = IMap . IntMap.mapMaybe f . intmap
328
286 329