diff options
Diffstat (limited to 'IntMapClass.hs')
-rw-r--r-- | IntMapClass.hs | 83 |
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 | ||
202 | mapAccum :: (t -> b -> (t, a)) -> t -> IMap k b -> (t, IMap k a) | 202 | mapAccum :: (t -> b -> (t, a)) -> t -> IMap k b -> (t, IMap k a) |
203 | mapAccum f a m = second IMap $ IntMap.mapAccum f a (intmap m) | 203 | mapAccum f a m = second IMap $ IntMap.mapAccum f a (intmap m) |
204 | |||
205 | mapAccumWithKey :: Coercible Int k => | ||
206 | (t -> k -> b -> (t, a)) -> t -> IMap k b -> (t, IMap k a) | ||
207 | mapAccumWithKey f a m = second IMap $ IntMap.mapAccumWithKey f' a (intmap m) | ||
208 | where f' a k b = f a (coerce k) b | ||
209 | |||
210 | |||
211 | mapAccumRWithKey :: Coercible Int k => | ||
212 | (t -> k -> b -> (t, a)) -> t -> IMap k b -> (t, IMap k a) | ||
213 | mapAccumRWithKey f a m = second IMap $ IntMap.mapAccumRWithKey f' a (intmap m) | ||
214 | where f' a k b = f a (coerce k) b | ||
215 | |||
216 | mapKeys :: (Coercible Int k1, Coercible k2 Int) => | ||
217 | (k1 -> k2) -> IMap k1 a -> IMap k2 a | ||
218 | mapKeys f = IMap . adapt_m (IntMap.mapKeys (coerce . f . coerce)) | ||
219 | |||
220 | mapKeysWith :: (Coercible Int k1, Coercible k2 Int) => | ||
221 | (a->a->a) -> (k1 -> k2) -> IMap k1 a -> IMap k2 a | ||
222 | mapKeysWith c f = IMap . adapt_m (IntMap.mapKeysWith c (coerce . f . coerce)) | ||
223 | |||
224 | mapKeysMonotonic :: (Coercible Int k1, Coercible k2 Int) => | ||
225 | (k1 -> k2) -> IMap k1 a -> IMap k2 a | ||
226 | mapKeysMonotonic f = IMap . adapt_m (IntMap.mapKeysMonotonic (coerce . f . coerce)) | ||
227 | |||
228 | foldr :: (a -> x -> x) -> x -> IMap k a -> x | ||
229 | foldr f b = adapt_m (IntMap.foldr f b) | ||
230 | |||
231 | foldl :: (x -> a -> x) -> x -> IMap k a -> x | ||
232 | foldl f a = adapt_m (IntMap.foldl f a) | ||
233 | |||
234 | foldrWithKey :: Coercible Int b => (b -> a -> x -> x) -> x -> IMap k a -> x | ||
235 | foldrWithKey f b = adapt_m (IntMap.foldrWithKey (f . coerce) b) | ||
236 | |||
237 | foldlWithKey :: | ||
238 | Coercible Int k => (x -> k -> a -> x) -> x -> IMap k a -> x | ||
239 | foldlWithKey f a = adapt_m (IntMap.foldlWithKey f' a) where f' a = f a . coerce | ||
240 | |||
241 | #if MIN_VERSION_containers(0,5,3) | ||
242 | foldMapWithKey :: (Monoid m, Coercible k Int) => (k -> a -> m) -> IMap k a -> m | ||
243 | foldMapWithKey f = adapt_m (IntMap.foldMapWithKey $ f . coerce) | ||
244 | #endif | ||
245 | |||
246 | foldr' :: (a -> x -> x) -> x -> IMap k a -> x | ||
247 | foldr' f b = adapt_m (IntMap.foldr' f b) | ||
248 | |||
249 | foldl' :: (a -> x -> a) -> a -> IMap k x -> a | ||
250 | foldl' f b = adapt_m (IntMap.foldl' f b) | ||
251 | |||
252 | foldrWithKey' :: Coercible Int b => (b -> a -> x -> x) -> x -> IMap k a -> x | ||
253 | foldrWithKey' f b = adapt_m (IntMap.foldrWithKey' (f . coerce) b) | ||
254 | |||
255 | foldlWithKey' :: | ||
256 | Coercible Int k => (x -> k -> a -> x) -> x -> IMap k a -> x | ||
257 | foldlWithKey' f a = adapt_m (IntMap.foldlWithKey' f' a) where f' a = f a . coerce | ||
258 | |||
259 | elems :: IMap k a -> [a] | ||
260 | elems = IntMap.elems . intmap | ||
261 | |||
262 | keys :: Coercible [Int] [k] => IMap k a -> [k] | ||
263 | keys = coerce . IntMap.keys . intmap | ||
264 | |||
265 | assocs :: Coercible [(Int,a)] [(k,a)] => IMap k a -> [(k, a)] | ||
266 | assocs = 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 | |||
272 | toList :: Coercible [(Int,a)] [(k,a)] => IMap k a -> [(k, a)] | ||
273 | toList = coerce . IntMap.toList . intmap | ||
274 | |||
275 | fromList :: Coercible [(k,a)] [(Int,a)] => [(k, a)] -> IMap k a | ||
276 | fromList = IMap . IntMap.fromList . coerce | ||
277 | |||
278 | fromListWith :: Coercible [(k,a)] [(Int,a)] => (a -> a -> a) -> [(k, a)] -> IMap k a | ||
279 | fromListWith f = IMap . IntMap.fromListWith f . coerce | ||
280 | |||
281 | fromListWithKey :: ( Coercible Int k | ||
282 | , Coercible [(k,a)] [(Int,a)] ) => | ||
283 | (k -> a -> a -> a) -> [(k, a)] -> IMap k a | ||
284 | fromListWithKey f = IMap . IntMap.fromListWithKey (f . coerce) . coerce | ||
285 | |||
286 | |||