@@ -0,0 +1,668 @@
2+{-# LANGUAGE ScopedTypeVariables #-}
3+{-# LANGUAGE MultiParamTypeClasses #-}
4+{-# LANGUAGE TypeFamilies #-}
5+{-# LANGUAGE FlexibleInstances #-}
6+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
7+{-# LANGUAGE DeriveTraversable #-}
8+{-# LANGUAGE DeriveDataTypeable #-}
9+{-# LANGUAGE StandaloneDeriving #-}
11+-- | This module provides a 'Data.IntMap' variant which uses the value's
12+-- 'Monoid' instance to accumulate conflicting entries when merging
15+-- While some functions mirroring those of 'Data.IntMap' are provided
16+-- here for convenience, more specialized needs will likely want to use
17+-- either the 'Newtype' or 'Wrapped' instances to manipulate the
20+module Data.IntMap.Monoidal
22+ -- * Often-needed functions
64+ , fromDistinctAscList
71+ , insertLookupWithKey
75+ , intersectionWithKey
119+ , updateLookupWithKey
130+import Prelude hiding (null, lookup, map, foldl, foldr, filter)
132+import Data.Coerce (coerce)
133+import Data.IntSet (IntSet)
134+import Data.Semigroup
135+import Data.Foldable (Foldable)
136+import Data.Traversable (Traversable)
137+import Control.Applicative (Applicative, pure)
138+import Data.Data (Data)
139+import Data.Typeable (Typeable)
141+#if MIN_VERSION_base(4,7,0)
142+import qualified GHC.Exts as IsList
145+import Control.DeepSeq
146+import qualified Data.IntMap as M
148+import Control.Newtype
149+import Data.Aeson(FromJSON, ToJSON, FromJSON1, ToJSON1)
150+#if MIN_VERSION_containers(0,5,9)
151+import Data.Functor.Classes
155+-- | An 'IntMap' with monoidal accumulation
156+newtype MonoidalIntMap a = MonoidalIntMap { getMonoidalIntMap :: M.IntMap a }
157+ deriving (Show, Read, Functor, Eq, Ord, NFData,
158+ Foldable, Traversable,
159+ FromJSON, ToJSON, FromJSON1, ToJSON1,
160+ Data, Typeable, Align)
162+#if MIN_VERSION_containers(0,5,9)
163+deriving instance Eq1 MonoidalIntMap
164+deriving instance Ord1 MonoidalIntMap
165+deriving instance Show1 MonoidalIntMap
168+type instance Index (MonoidalIntMap a) = Int
169+type instance IxValue (MonoidalIntMap a) = a
170+instance Ixed (MonoidalIntMap a) where
171+ ix k f (MonoidalIntMap m) = case M.lookup k m of
172+ Just v -> f v <&> \v' -> MonoidalIntMap (M.insert k v' m)
173+ Nothing -> pure (MonoidalIntMap m)
176+instance At (MonoidalIntMap a) where
177+ at k f (MonoidalIntMap m) = f mv <&> \r -> case r of
178+ Nothing -> maybe (MonoidalIntMap m) (const (MonoidalIntMap $ M.delete k m)) mv
179+ Just v' -> MonoidalIntMap $ M.insert k v' m
180+ where mv = M.lookup k m
183+instance Each (MonoidalIntMap a) (MonoidalIntMap b) a b
185+instance FunctorWithIndex Int MonoidalIntMap
186+instance FoldableWithIndex Int MonoidalIntMap
187+instance TraversableWithIndex Int MonoidalIntMap where
188+ itraverse f (MonoidalIntMap m) = fmap MonoidalIntMap $ itraverse f m
189+ {-# INLINE itraverse #-}
191+instance TraverseMin Int MonoidalIntMap where
192+ traverseMin f (MonoidalIntMap m) = fmap MonoidalIntMap $ traverseMin f m
193+ {-# INLINE traverseMin #-}
194+instance TraverseMax Int MonoidalIntMap where
195+ traverseMax f (MonoidalIntMap m) = fmap MonoidalIntMap $ traverseMax f m
196+ {-# INLINE traverseMax #-}
198+instance AsEmpty (MonoidalIntMap a) where
199+ _Empty = nearly (MonoidalIntMap M.empty) (M.null . unpack)
200+ {-# INLINE _Empty #-}
202+instance Wrapped (MonoidalIntMap a) where
203+ type Unwrapped (MonoidalIntMap a) = M.IntMap a
204+ _Wrapped' = iso unpack pack
205+ {-# INLINE _Wrapped' #-}
207+instance Semigroup a => Semigroup (MonoidalIntMap a) where
208+ MonoidalIntMap a <> MonoidalIntMap b = MonoidalIntMap $ M.unionWith (<>) a b
211+instance Semigroup a => Monoid (MonoidalIntMap a) where
212+ mempty = MonoidalIntMap mempty
213+ {-# INLINE mempty #-}
214+#if !(MIN_VERSION_base(4,11,0))
215+ mappend (MonoidalIntMap a) (MonoidalIntMap b) = MonoidalIntMap $ M.unionWith (<>) a b
216+ {-# INLINE mappend #-}
219+instance Newtype (MonoidalIntMap a) (M.IntMap a) where
220+ pack = MonoidalIntMap
222+ unpack (MonoidalIntMap a) = a
223+ {-# INLINE unpack #-}
225+#if MIN_VERSION_base(4,7,0)
226+instance Semigroup a => IsList.IsList (MonoidalIntMap a) where
227+ type Item (MonoidalIntMap a) = (Int, a)
228+ fromList = MonoidalIntMap . M.fromListWith (<>)
229+ {-# INLINE fromList #-}
230+ toList = M.toList . unpack
231+ {-# INLINE toList #-}
234+-- | /O(1)/. A map with a single element.
235+singleton :: Int -> a -> MonoidalIntMap a
236+singleton k a = MonoidalIntMap $ M.singleton k a
237+{-# INLINE singleton #-}
239+-- | /O(1)/. The number of elements in the map.
240+size :: MonoidalIntMap a -> Int
241+size = M.size . unpack
244+-- | /O(log n)/. Is the key a member of the map? See also 'notMember'.
245+member :: Int -> MonoidalIntMap a -> Bool
246+member k = M.member k . unpack
247+{-# INLINE member #-}
249+-- | /O(log n)/. Is the key not a member of the map? See also 'member'.
250+notMember :: Int -> MonoidalIntMap a -> Bool
251+notMember k = not . M.member k . unpack
252+{-# INLINE notMember #-}
254+-- | /O(log n)/. The expression @('findWithDefault' def k map)@ returns
255+-- the value at key @k@ or returns default value @def@
256+-- when the key is not in the map.
257+findWithDefault :: forall a. a -> Int -> MonoidalIntMap a -> a
258+findWithDefault def k = M.findWithDefault def k . unpack
259+{-# INLINE findWithDefault #-}
261+-- | /O(log n)/. Delete a key and its value from the map. When the key is not
262+-- a member of the map, the original map is returned.
263+delete :: Int -> MonoidalIntMap a -> MonoidalIntMap a
264+delete k = _Wrapping' MonoidalIntMap %~ M.delete k
265+{-# INLINE delete #-}
267+-- | /O(n)/. Return all elements of the map and their keys
268+assocs :: MonoidalIntMap a -> [(Int,a)]
269+assocs = M.assocs . unpack
270+{-# INLINE assocs #-}
272+-- | /O(n)/. Return all elements of the map in the ascending order of their
273+-- keys. Subject to list fusion.
274+elems :: MonoidalIntMap a -> [a]
275+elems = M.elems . unpack
278+-- | /O(n)/. Return all keys of the map in ascending order. Subject to list
280+keys :: MonoidalIntMap a -> [Int]
281+keys = M.keys . unpack
284+(!) :: forall a. MonoidalIntMap a -> Int -> a
285+(!) = coerce ((M.!) :: M.IntMap a -> Int -> a)
288+(\\) :: forall a b. MonoidalIntMap a -> MonoidalIntMap b -> MonoidalIntMap a
289+(\\) = coerce ((M.\\) :: M.IntMap a -> M.IntMap b -> M.IntMap a)
292+null :: forall a. MonoidalIntMap a -> Bool
293+null = coerce (M.null :: M.IntMap a -> Bool)
296+lookup :: forall a. Int -> MonoidalIntMap a -> Maybe a
297+lookup = coerce (M.lookup :: Int -> M.IntMap a -> Maybe a)
298+{-# INLINE lookup #-}
300+lookupLT :: forall a. Int -> MonoidalIntMap a -> Maybe (Int, a)
301+lookupLT = coerce (M.lookupLT :: Int -> M.IntMap a -> Maybe (Int,a))
302+{-# INLINE lookupLT #-}
304+lookupGT :: forall a. Int -> MonoidalIntMap a -> Maybe (Int, a)
305+lookupGT = coerce (M.lookupGT :: Int -> M.IntMap a -> Maybe (Int,a))
306+{-# INLINE lookupGT #-}
308+lookupLE :: forall a. Int -> MonoidalIntMap a -> Maybe (Int, a)
309+lookupLE = coerce (M.lookupLE :: Int -> M.IntMap a -> Maybe (Int,a))
310+{-# INLINE lookupLE #-}
312+lookupGE :: forall a. Int -> MonoidalIntMap a -> Maybe (Int, a)
313+lookupGE = coerce (M.lookupGE :: Int -> M.IntMap a -> Maybe (Int,a))
314+{-# INLINE lookupGE #-}
316+empty :: forall a. MonoidalIntMap a
317+empty = coerce (M.empty :: M.IntMap a)
320+insert :: forall a. Int -> a -> MonoidalIntMap a -> MonoidalIntMap a
321+insert = coerce (M.insert :: Int -> a -> M.IntMap a -> M.IntMap a)
322+{-# INLINE insert #-}
324+insertWith :: forall a. (a -> a -> a) -> Int -> a -> MonoidalIntMap a -> MonoidalIntMap a
325+insertWith = coerce (M.insertWith :: (a -> a -> a) -> Int -> a -> M.IntMap a -> M.IntMap a)
326+{-# INLINE insertWith #-}
328+insertWithKey :: forall a. (Int -> a -> a -> a) -> Int -> a -> MonoidalIntMap a -> MonoidalIntMap a
329+insertWithKey = coerce (M.insertWithKey :: (Int -> a -> a -> a) -> Int -> a -> M.IntMap a -> M.IntMap a)
330+{-# INLINE insertWithKey #-}
332+insertLookupWithKey :: forall a. (Int -> a -> a -> a) -> Int -> a -> MonoidalIntMap a -> (Maybe a, MonoidalIntMap a)
333+insertLookupWithKey = coerce (M.insertLookupWithKey :: (Int -> a -> a -> a) -> Int -> a -> M.IntMap a -> (Maybe a, M.IntMap a))
334+{-# INLINE insertLookupWithKey #-}
336+adjust :: forall a. (a -> a) -> Int -> MonoidalIntMap a -> MonoidalIntMap a
337+adjust = coerce (M.adjust :: (a -> a) -> Int -> M.IntMap a -> M.IntMap a)
338+{-# INLINE adjust #-}
340+adjustWithKey :: forall a. (Int -> a -> a) -> Int -> MonoidalIntMap a -> MonoidalIntMap a
341+adjustWithKey = coerce (M.adjustWithKey :: (Int -> a -> a) -> Int -> M.IntMap a -> M.IntMap a)
342+{-# INLINE adjustWithKey #-}
344+update :: forall a. (a -> Maybe a) -> Int -> MonoidalIntMap a -> MonoidalIntMap a
345+update = coerce (M.update :: (a -> Maybe a) -> Int -> M.IntMap a -> M.IntMap a)
346+{-# INLINE update #-}
348+updateWithKey :: forall a. (Int -> a -> Maybe a) -> Int -> MonoidalIntMap a -> MonoidalIntMap a
349+updateWithKey = coerce (M.updateWithKey :: (Int -> a -> Maybe a) -> Int -> M.IntMap a -> M.IntMap a)
350+{-# INLINE updateWithKey #-}
352+updateLookupWithKey :: forall a. (Int -> a -> Maybe a) -> Int -> MonoidalIntMap a -> (Maybe a, MonoidalIntMap a)
353+updateLookupWithKey = coerce (M.updateLookupWithKey :: (Int -> a -> Maybe a) -> Int -> M.IntMap a -> (Maybe a, M.IntMap a))
354+{-# INLINE updateLookupWithKey #-}
356+alter :: forall a. (Maybe a -> Maybe a) -> Int -> MonoidalIntMap a -> MonoidalIntMap a
357+alter = coerce (M.alter :: (Maybe a -> Maybe a) -> Int -> M.IntMap a -> M.IntMap a)
360+unionWith :: forall a. (a -> a -> a) -> MonoidalIntMap a -> MonoidalIntMap a -> MonoidalIntMap a
361+unionWith = coerce (M.unionWith :: (a -> a -> a) -> M.IntMap a -> M.IntMap a -> M.IntMap a)
362+{-# INLINE unionWith #-}
364+unionWithKey :: forall a. (Int -> a -> a -> a) -> MonoidalIntMap a -> MonoidalIntMap a -> MonoidalIntMap a
365+unionWithKey = coerce (M.unionWithKey :: (Int -> a -> a -> a) -> M.IntMap a -> M.IntMap a -> M.IntMap a)
366+{-# INLINE unionWithKey #-}
368+unionsWith :: forall a. (a -> a -> a) -> [MonoidalIntMap a] -> MonoidalIntMap a
369+unionsWith = coerce (M.unionsWith :: (a -> a -> a) -> [M.IntMap a] -> M.IntMap a)
370+{-# INLINE unionsWith #-}
372+difference :: forall a b. MonoidalIntMap a -> MonoidalIntMap b -> MonoidalIntMap a
374+{-# INLINE difference #-}
376+differenceWith :: forall a b. (a -> b -> Maybe a) -> MonoidalIntMap a -> MonoidalIntMap b -> MonoidalIntMap a
377+differenceWith = coerce (M.differenceWith :: (a -> b -> Maybe a) -> M.IntMap a -> M.IntMap b -> M.IntMap a)
378+{-# INLINE differenceWith #-}
380+differenceWithKey :: forall a b. (Int -> a -> b -> Maybe a) -> MonoidalIntMap a -> MonoidalIntMap b -> MonoidalIntMap a
381+differenceWithKey = coerce (M.differenceWithKey :: (Int -> a -> b -> Maybe a) -> M.IntMap a -> M.IntMap b -> M.IntMap a)
382+{-# INLINE differenceWithKey #-}
384+intersectionWith :: forall a b c. (a -> b -> c) -> MonoidalIntMap a -> MonoidalIntMap b -> MonoidalIntMap c
385+intersectionWith = coerce (M.intersectionWith :: (a -> b -> c) -> M.IntMap a -> M.IntMap b -> M.IntMap c)
386+{-# INLINE intersectionWith #-}
388+intersectionWithKey :: forall a b c. (Int -> a -> b -> c) -> MonoidalIntMap a -> MonoidalIntMap b -> MonoidalIntMap c
389+intersectionWithKey = coerce (M.intersectionWithKey :: (Int -> a -> b -> c) -> M.IntMap a -> M.IntMap b -> M.IntMap c)
390+{-# INLINE intersectionWithKey #-}
392+mergeWithKey :: forall a b c. (Int -> a -> b -> Maybe c) -> (MonoidalIntMap a -> MonoidalIntMap c) -> (MonoidalIntMap b -> MonoidalIntMap c) -> MonoidalIntMap a -> MonoidalIntMap b -> MonoidalIntMap c
393+mergeWithKey = coerce (M.mergeWithKey :: (Int -> a -> b -> Maybe c) -> (M.IntMap a -> M.IntMap c) -> (M.IntMap b -> M.IntMap c) -> M.IntMap a -> M.IntMap b -> M.IntMap c)
394+{-# INLINE mergeWithKey #-}
396+map :: (a -> b) -> MonoidalIntMap a -> MonoidalIntMap b
400+mapWithKey :: forall a b. (Int -> a -> b) -> MonoidalIntMap a -> MonoidalIntMap b
401+mapWithKey = coerce (M.mapWithKey :: (Int -> a -> b) -> M.IntMap a -> M.IntMap b)
402+{-# INLINE mapWithKey #-}
404+traverseWithKey :: Applicative t => (Int -> a -> t b) -> MonoidalIntMap a -> t (MonoidalIntMap b)
405+traverseWithKey = itraverse
406+{-# INLINE traverseWithKey #-}
408+mapAccum :: forall a b c. (a -> b -> (a, c)) -> a -> MonoidalIntMap b -> (a, MonoidalIntMap c)
409+mapAccum = coerce (M.mapAccum :: (a -> b -> (a, c)) -> a -> M.IntMap b -> (a, M.IntMap c))
410+{-# INLINE mapAccum #-}
412+mapAccumWithKey :: forall a b c. (a -> Int -> b -> (a, c)) -> a -> MonoidalIntMap b -> (a, MonoidalIntMap c)
413+mapAccumWithKey = coerce (M.mapAccumWithKey :: (a -> Int -> b -> (a, c)) -> a -> M.IntMap b -> (a, M.IntMap c))
414+{-# INLINE mapAccumWithKey #-}
416+mapAccumRWithKey :: forall a b c. (a -> Int -> b -> (a, c)) -> a -> MonoidalIntMap b -> (a, MonoidalIntMap c)
417+mapAccumRWithKey = coerce (M.mapAccumRWithKey :: (a -> Int -> b -> (a, c)) -> a -> M.IntMap b -> (a, M.IntMap c))
418+{-# INLINE mapAccumRWithKey #-}
420+mapKeys :: forall a. (Int -> Int) -> MonoidalIntMap a -> MonoidalIntMap a
421+mapKeys = coerce (M.mapKeys :: (Int -> Int) -> M.IntMap a -> M.IntMap a)
422+{-# INLINE mapKeys #-}
424+mapKeysWith :: forall a. (a -> a -> a) -> (Int -> Int) -> MonoidalIntMap a -> MonoidalIntMap a
425+mapKeysWith = coerce (M.mapKeysWith :: (a -> a -> a) -> (Int -> Int) -> M.IntMap a -> M.IntMap a)
426+{-# INLINE mapKeysWith #-}
428+mapKeysMonotonic :: forall a. (Int -> Int) -> MonoidalIntMap a -> MonoidalIntMap a
429+mapKeysMonotonic = coerce (M.mapKeysMonotonic :: (Int -> Int) -> M.IntMap a -> M.IntMap a)
430+{-# INLINE mapKeysMonotonic #-}
432+foldr :: forall a b. (a -> b -> b) -> b -> MonoidalIntMap a -> b
433+foldr = coerce (M.foldr :: (a -> b -> b) -> b -> M.IntMap a -> b)
436+foldl :: forall a b. (a -> b -> a) -> a -> MonoidalIntMap b -> a
437+foldl = coerce (M.foldl :: (a -> b -> a) -> a -> M.IntMap b -> a)
440+foldrWithKey :: forall a b. (Int -> a -> b -> b) -> b -> MonoidalIntMap a -> b
441+foldrWithKey = coerce (M.foldrWithKey :: (Int -> a -> b -> b) -> b -> M.IntMap a -> b)
442+{-# INLINE foldrWithKey #-}
444+foldlWithKey :: forall a b. (a -> Int -> b -> a) -> a -> MonoidalIntMap b -> a
445+foldlWithKey = coerce (M.foldlWithKey :: (a -> Int -> b -> a) -> a -> M.IntMap b -> a)
446+{-# INLINE foldlWithKey #-}
448+foldMapWithKey :: forall a m. Monoid m => (Int -> a -> m) -> MonoidalIntMap a -> m
449+foldMapWithKey = coerce (M.foldMapWithKey :: Monoid m => (Int -> a -> m) -> M.IntMap a -> m)
450+{-# INLINE foldMapWithKey #-}
452+foldr' :: forall a b. (a -> b -> b) -> b -> MonoidalIntMap a -> b
453+foldr' = coerce (M.foldr' :: (a -> b -> b) -> b -> M.IntMap a -> b)
454+{-# INLINE foldr' #-}
456+foldl' :: forall a b. (a -> b -> a) -> a -> MonoidalIntMap b -> a
457+foldl' = coerce (M.foldl' :: (a -> b -> a) -> a -> M.IntMap b -> a)
458+{-# INLINE foldl' #-}
460+foldrWithKey' :: forall a b. (Int -> a -> b -> b) -> b -> MonoidalIntMap a -> b
461+foldrWithKey' = coerce (M.foldrWithKey' :: (Int -> a -> b -> b) -> b -> M.IntMap a -> b)
462+{-# INLINE foldrWithKey' #-}
464+foldlWithKey' :: forall a b. (a -> Int -> b -> a) -> a -> MonoidalIntMap b -> a
465+foldlWithKey' = coerce (M.foldlWithKey' :: (a -> Int -> b -> a) -> a -> M.IntMap b -> a)
466+{-# INLINE foldlWithKey' #-}
468+keysSet :: forall a. MonoidalIntMap a -> IntSet
469+keysSet = coerce (M.keysSet :: M.IntMap a -> IntSet)
470+{-# INLINE keysSet #-}
472+fromSet :: forall a. (Int -> a) -> IntSet -> MonoidalIntMap a
473+fromSet = coerce (M.fromSet :: (Int -> a) -> IntSet -> M.IntMap a)
474+{-# INLINE fromSet #-}
476+toList :: forall a. MonoidalIntMap a -> [(Int, a)]
477+toList = coerce (M.toList :: M.IntMap a -> [(Int, a)])
478+{-# INLINE toList #-}
480+fromList :: forall a. Semigroup a => [(Int, a)] -> MonoidalIntMap a
481+fromList = fromListWith (<>)
482+{-# INLINE fromList #-}
484+fromListWith :: forall a. (a -> a -> a) -> [(Int, a)] -> MonoidalIntMap a
485+fromListWith = coerce (M.fromListWith :: (a -> a -> a) -> [(Int, a)] -> M.IntMap a)
486+{-# INLINE fromListWith #-}
488+fromListWithKey :: forall a. (Int -> a -> a -> a) -> [(Int, a)] -> MonoidalIntMap a
489+fromListWithKey = coerce (M.fromListWithKey :: (Int -> a -> a -> a) -> [(Int, a)] -> M.IntMap a)
490+{-# INLINE fromListWithKey #-}
492+toAscList :: forall a. MonoidalIntMap a -> [(Int, a)]
493+toAscList = coerce (M.toAscList :: M.IntMap a -> [(Int, a)])
494+{-# INLINE toAscList #-}
496+toDescList :: forall a. MonoidalIntMap a -> [(Int, a)]
497+toDescList = coerce (M.toDescList :: M.IntMap a -> [(Int, a)])
498+{-# INLINE toDescList #-}
500+fromAscList :: forall a. Semigroup a => [(Int, a)] -> MonoidalIntMap a
501+fromAscList = fromAscListWith (<>)
502+{-# INLINE fromAscList #-}
504+fromAscListWith :: forall a. (a -> a -> a) -> [(Int, a)] -> MonoidalIntMap a
505+fromAscListWith = coerce (M.fromAscListWith :: (a -> a -> a) -> [(Int, a)] -> M.IntMap a)
506+{-# INLINE fromAscListWith #-}
508+fromAscListWithKey :: forall a. (Int -> a -> a -> a) -> [(Int, a)] -> MonoidalIntMap a
509+fromAscListWithKey = coerce (M.fromAscListWithKey :: (Int -> a -> a -> a) -> [(Int, a)] -> M.IntMap a)
510+{-# INLINE fromAscListWithKey #-}
512+fromDistinctAscList :: forall a. [(Int, a)] -> MonoidalIntMap a
513+fromDistinctAscList = coerce (M.fromDistinctAscList :: [(Int, a)] -> M.IntMap a)
514+{-# INLINE fromDistinctAscList #-}
516+fromDistinctList :: forall a. [(Int, a)] -> MonoidalIntMap a
517+fromDistinctList = coerce (M.fromList :: [(Int, a)] -> M.IntMap a)
518+{-# INLINE fromDistinctList #-}
520+filter :: forall a. (a -> Bool) -> MonoidalIntMap a -> MonoidalIntMap a
521+filter = coerce (M.filter :: (a -> Bool) -> M.IntMap a -> M.IntMap a)
522+{-# INLINE filter #-}
524+filterWithKey :: forall a. (Int -> a -> Bool) -> MonoidalIntMap a -> MonoidalIntMap a
525+filterWithKey = coerce (M.filterWithKey :: (Int -> a -> Bool) -> M.IntMap a -> M.IntMap a)
526+{-# INLINE filterWithKey #-}
528+partition :: forall a. (a -> Bool) -> MonoidalIntMap a -> (MonoidalIntMap a, MonoidalIntMap a)
529+partition = coerce (M.partition :: (a -> Bool) -> M.IntMap a -> (M.IntMap a, M.IntMap a))
530+{-# INLINE partition #-}
532+partitionWithKey :: forall a. (Int -> a -> Bool) -> MonoidalIntMap a -> (MonoidalIntMap a, MonoidalIntMap a)
533+partitionWithKey = coerce (M.partitionWithKey :: (Int -> a -> Bool) -> M.IntMap a -> (M.IntMap a, M.IntMap a))
534+{-# INLINE partitionWithKey #-}
536+mapMaybe :: forall a b. (a -> Maybe b) -> MonoidalIntMap a -> MonoidalIntMap b
537+mapMaybe = coerce (M.mapMaybe :: (a -> Maybe b) -> M.IntMap a -> M.IntMap b)
538+{-# INLINE mapMaybe #-}
540+mapMaybeWithKey :: forall a b. (Int -> a -> Maybe b) -> MonoidalIntMap a -> MonoidalIntMap b
541+mapMaybeWithKey = coerce (M.mapMaybeWithKey :: (Int -> a -> Maybe b) -> M.IntMap a -> M.IntMap b)
542+{-# INLINE mapMaybeWithKey #-}
544+mapEither :: forall a b c. (a -> Either b c) -> MonoidalIntMap a -> (MonoidalIntMap b, MonoidalIntMap c)
545+mapEither = coerce (M.mapEither :: (a -> Either b c) -> M.IntMap a -> (M.IntMap b, M.IntMap c))
546+{-# INLINE mapEither #-}
548+mapEitherWithKey :: forall a b c. (Int -> a -> Either b c) -> MonoidalIntMap a -> (MonoidalIntMap b, MonoidalIntMap c)
549+mapEitherWithKey = coerce (M.mapEitherWithKey :: (Int -> a -> Either b c) -> M.IntMap a -> (M.IntMap b, M.IntMap c))
550+{-# INLINE mapEitherWithKey #-}
552+split :: forall a. Int -> MonoidalIntMap a -> (MonoidalIntMap a, MonoidalIntMap a)
553+split = coerce (M.split :: Int -> M.IntMap a -> (M.IntMap a, M.IntMap a))
556+splitLookup :: forall a. Int -> MonoidalIntMap a -> (MonoidalIntMap a, Maybe a, MonoidalIntMap a)
557+splitLookup = coerce (M.splitLookup :: Int -> M.IntMap a -> (M.IntMap a, Maybe a, M.IntMap a))
558+{-# INLINE splitLookup #-}
560+splitRoot :: forall a. MonoidalIntMap a -> [MonoidalIntMap a]
561+splitRoot = coerce (M.splitRoot :: M.IntMap a -> [M.IntMap a])
562+{-# INLINE splitRoot #-}
564+isSubmapOf :: forall a. Eq a => MonoidalIntMap a -> MonoidalIntMap a -> Bool
565+isSubmapOf = coerce (M.isSubmapOf :: M.IntMap a -> M.IntMap a -> Bool)
566+{-# INLINE isSubmapOf #-}
568+isSubmapOfBy :: forall a b. (a -> b -> Bool) -> MonoidalIntMap a -> MonoidalIntMap b -> Bool
569+isSubmapOfBy = coerce (M.isSubmapOfBy :: (a -> b -> Bool) -> M.IntMap a -> M.IntMap b -> Bool)
570+{-# INLINE isSubmapOfBy #-}
572+isProperSubmapOf :: forall a. Eq a => MonoidalIntMap a -> MonoidalIntMap a -> Bool
573+isProperSubmapOf = coerce (M.isProperSubmapOf :: M.IntMap a -> M.IntMap a -> Bool)
574+{-# INLINE isProperSubmapOf #-}
576+isProperSubmapOfBy :: forall a b. (a -> b -> Bool) -> MonoidalIntMap a -> MonoidalIntMap b -> Bool
577+isProperSubmapOfBy = coerce (M.isProperSubmapOfBy :: (a -> b -> Bool) -> M.IntMap a -> M.IntMap b -> Bool)
578+{-# INLINE isProperSubmapOfBy #-}
580+-- lookupIndex :: forall a. Ord k => k -> MonoidalIntMap a -> Maybe Int
581+-- lookupIndex = coerce (M.lookupIndex :: k -> M.IntMap a -> Maybe Int)
582+-- {-# INLINE lookupIndex #-}
584+-- findIndex :: forall a. Ord k => k -> MonoidalIntMap a -> Int
585+-- findIndex = coerce (M.findIndex :: k -> M.IntMap a -> Int)
586+-- {-# INLINE findIndex #-}
588+-- elemAt :: forall a. Int -> MonoidalIntMap a -> (Int, a)
589+-- elemAt = coerce (M.elemAt :: Int -> M.IntMap a -> (Int, a))
590+-- {-# INLINE elemAt #-}
592+-- updateAt :: forall a. (Int -> a -> Maybe a) -> Int -> MonoidalIntMap a -> MonoidalIntMap a
593+-- updateAt = coerce (M.updateAt :: (Int -> a -> Maybe a) -> Int -> M.IntMap a -> M.IntMap a)
594+-- {-# INLINE updateAt #-}
596+-- deleteAt :: forall a. Int -> MonoidalIntMap a -> MonoidalIntMap a
597+-- deleteAt = coerce (M.deleteAt :: Int -> M.IntMap a -> M.IntMap a)
598+-- {-# INLINE deleteAt #-}
600+findMin :: forall a. MonoidalIntMap a -> (Int, a)
601+findMin = coerce (M.findMin :: M.IntMap a -> (Int, a))
602+{-# INLINE findMin #-}
604+findMax :: forall a. MonoidalIntMap a -> (Int, a)
605+findMax = coerce (M.findMax :: M.IntMap a -> (Int, a))
606+{-# INLINE findMax #-}
608+deleteMin :: forall a. MonoidalIntMap a -> MonoidalIntMap a
609+deleteMin = coerce (M.deleteMin :: M.IntMap a -> M.IntMap a)
610+{-# INLINE deleteMin #-}
612+deleteMax :: forall a. MonoidalIntMap a -> MonoidalIntMap a
613+deleteMax = coerce (M.deleteMax :: M.IntMap a -> M.IntMap a)
614+{-# INLINE deleteMax #-}
616+deleteFindMin :: forall a. MonoidalIntMap a -> ((Int, a), MonoidalIntMap a)
617+deleteFindMin = coerce (M.deleteFindMin :: M.IntMap a -> ((Int, a), M.IntMap a))
618+{-# INLINE deleteFindMin #-}
620+deleteFindMax :: forall a. MonoidalIntMap a -> ((Int, a), MonoidalIntMap a)
621+deleteFindMax = coerce (M.deleteFindMax :: M.IntMap a -> ((Int, a), M.IntMap a))
622+{-# INLINE deleteFindMax #-}
624+updateMin :: forall a. (a -> Maybe a) -> MonoidalIntMap a -> MonoidalIntMap a
625+updateMin = coerce (M.updateMin :: (a -> Maybe a) -> M.IntMap a -> M.IntMap a)
626+{-# INLINE updateMin #-}
628+updateMax :: forall a. (a -> Maybe a) -> MonoidalIntMap a -> MonoidalIntMap a
629+updateMax = coerce (M.updateMax :: (a -> Maybe a) -> M.IntMap a -> M.IntMap a)
630+{-# INLINE updateMax #-}
632+updateMinWithKey :: forall a. (Int -> a -> Maybe a) -> MonoidalIntMap a -> MonoidalIntMap a
633+updateMinWithKey = coerce (M.updateMinWithKey :: (Int -> a -> Maybe a) -> M.IntMap a -> M.IntMap a)
634+{-# INLINE updateMinWithKey #-}
636+updateMaxWithKey :: forall a. (Int -> a -> Maybe a) -> MonoidalIntMap a -> MonoidalIntMap a
637+updateMaxWithKey = coerce (M.updateMaxWithKey :: (Int -> a -> Maybe a) -> M.IntMap a -> M.IntMap a)
638+{-# INLINE updateMaxWithKey #-}
640+minView :: forall a. MonoidalIntMap a -> Maybe (a, MonoidalIntMap a)
641+minView = coerce (M.minView :: M.IntMap a -> Maybe (a, M.IntMap a))
642+{-# INLINE minView #-}
644+maxView :: forall a. MonoidalIntMap a -> Maybe (a, MonoidalIntMap a)
645+maxView = coerce (M.maxView :: M.IntMap a -> Maybe (a, M.IntMap a))
646+{-# INLINE maxView #-}
648+minViewWithKey :: forall a. MonoidalIntMap a -> Maybe ((Int, a), MonoidalIntMap a)
649+minViewWithKey = coerce (M.minViewWithKey :: M.IntMap a -> Maybe ((Int, a), M.IntMap a))
650+{-# INLINE minViewWithKey #-}
652+maxViewWithKey :: forall a. MonoidalIntMap a -> Maybe ((Int, a), MonoidalIntMap a)
653+maxViewWithKey = coerce (M.maxViewWithKey :: M.IntMap a -> Maybe ((Int, a), M.IntMap a))
654+{-# INLINE maxViewWithKey #-}
656+-- showTree :: forall a. (Show k, Show a) => MonoidalIntMap a -> String
657+-- showTree = coerce (M.showTree :: (Show k, Show a) => M.IntMap a -> String)
658+-- {-# INLINE showTree #-}
660+-- showTreeWith :: forall a. (Int -> a -> String) -> Bool -> Bool -> MonoidalIntMap a -> String
661+-- showTreeWith = coerce (M.showTreeWith :: (Int -> a -> String) -> Bool -> Bool -> M.IntMap a -> String)
662+-- {-# INLINE showTreeWith #-}
664+--valid :: forall a. Ord k => MonoidalIntMap a -> Bool
665+--valid = coerce (M.valid :: Ord k => M.IntMap a -> Bool)
666+--{-# INLINE valid #-}