summaryrefslogtreecommitdiff
path: root/IntMapClass.hs
diff options
context:
space:
mode:
Diffstat (limited to 'IntMapClass.hs')
-rw-r--r--IntMapClass.hs83
1 files changed, 83 insertions, 0 deletions
diff --git a/IntMapClass.hs b/IntMapClass.hs
index 7c18de8..ce544f9 100644
--- a/IntMapClass.hs
+++ b/IntMapClass.hs
@@ -201,3 +201,86 @@ traverseWithKey f = fmap IMap . adapt_m (IntMap.traverseWithKey $ f . coerce)
201 201
202mapAccum :: (t -> b -> (t, a)) -> t -> IMap k b -> (t, IMap k a) 202mapAccum :: (t -> b -> (t, a)) -> t -> IMap k b -> (t, IMap k a)
203mapAccum f a m = second IMap $ IntMap.mapAccum f a (intmap m) 203mapAccum f a m = second IMap $ IntMap.mapAccum f a (intmap m)
204
205mapAccumWithKey :: Coercible Int k =>
206 (t -> k -> b -> (t, a)) -> t -> IMap k b -> (t, IMap k a)
207mapAccumWithKey f a m = second IMap $ IntMap.mapAccumWithKey f' a (intmap m)
208 where f' a k b = f a (coerce k) b
209
210
211mapAccumRWithKey :: Coercible Int k =>
212 (t -> k -> b -> (t, a)) -> t -> IMap k b -> (t, IMap k a)
213mapAccumRWithKey f a m = second IMap $ IntMap.mapAccumRWithKey f' a (intmap m)
214 where f' a k b = f a (coerce k) b
215
216mapKeys :: (Coercible Int k1, Coercible k2 Int) =>
217 (k1 -> k2) -> IMap k1 a -> IMap k2 a
218mapKeys f = IMap . adapt_m (IntMap.mapKeys (coerce . f . coerce))
219
220mapKeysWith :: (Coercible Int k1, Coercible k2 Int) =>
221 (a->a->a) -> (k1 -> k2) -> IMap k1 a -> IMap k2 a
222mapKeysWith c f = IMap . adapt_m (IntMap.mapKeysWith c (coerce . f . coerce))
223
224mapKeysMonotonic :: (Coercible Int k1, Coercible k2 Int) =>
225 (k1 -> k2) -> IMap k1 a -> IMap k2 a
226mapKeysMonotonic f = IMap . adapt_m (IntMap.mapKeysMonotonic (coerce . f . coerce))
227
228foldr :: (a -> x -> x) -> x -> IMap k a -> x
229foldr f b = adapt_m (IntMap.foldr f b)
230
231foldl :: (x -> a -> x) -> x -> IMap k a -> x
232foldl f a = adapt_m (IntMap.foldl f a)
233
234foldrWithKey :: Coercible Int b => (b -> a -> x -> x) -> x -> IMap k a -> x
235foldrWithKey f b = adapt_m (IntMap.foldrWithKey (f . coerce) b)
236
237foldlWithKey ::
238 Coercible Int k => (x -> k -> a -> x) -> x -> IMap k a -> x
239foldlWithKey f a = adapt_m (IntMap.foldlWithKey f' a) where f' a = f a . coerce
240
241#if MIN_VERSION_containers(0,5,3)
242foldMapWithKey :: (Monoid m, Coercible k Int) => (k -> a -> m) -> IMap k a -> m
243foldMapWithKey f = adapt_m (IntMap.foldMapWithKey $ f . coerce)
244#endif
245
246foldr' :: (a -> x -> x) -> x -> IMap k a -> x
247foldr' f b = adapt_m (IntMap.foldr' f b)
248
249foldl' :: (a -> x -> a) -> a -> IMap k x -> a
250foldl' f b = adapt_m (IntMap.foldl' f b)
251
252foldrWithKey' :: Coercible Int b => (b -> a -> x -> x) -> x -> IMap k a -> x
253foldrWithKey' f b = adapt_m (IntMap.foldrWithKey' (f . coerce) b)
254
255foldlWithKey' ::
256 Coercible Int k => (x -> k -> a -> x) -> x -> IMap k a -> x
257foldlWithKey' f a = adapt_m (IntMap.foldlWithKey' f' a) where f' a = f a . coerce
258
259elems :: IMap k a -> [a]
260elems = IntMap.elems . intmap
261
262keys :: Coercible [Int] [k] => IMap k a -> [k]
263keys = coerce . IntMap.keys . intmap
264
265assocs :: Coercible [(Int,a)] [(k,a)] => IMap k a -> [(k, a)]
266assocs = coerce . IntMap.assocs . intmap
267
268-- Not implementing... (doing it right requires wrapping IntSet)
269-- keysSet :: IntMap a -> IntSet
270-- fromSet :: (Key -> a) -> IntSet -> IntMap a
271
272toList :: Coercible [(Int,a)] [(k,a)] => IMap k a -> [(k, a)]
273toList = coerce . IntMap.toList . intmap
274
275fromList :: Coercible [(k,a)] [(Int,a)] => [(k, a)] -> IMap k a
276fromList = IMap . IntMap.fromList . coerce
277
278fromListWith :: Coercible [(k,a)] [(Int,a)] => (a -> a -> a) -> [(k, a)] -> IMap k a
279fromListWith f = IMap . IntMap.fromListWith f . coerce
280
281fromListWithKey :: ( Coercible Int k
282 , Coercible [(k,a)] [(Int,a)] ) =>
283 (k -> a -> a -> a) -> [(k, a)] -> IMap k a
284fromListWithKey f = IMap . IntMap.fromListWithKey (f . coerce) . coerce
285
286