@@ -1,12 +1,10 @@
11{-# LANGUAGE CPP #-}
2−{-# LANGUAGE ScopedTypeVariables #-}
32{-# LANGUAGE MultiParamTypeClasses #-}
43{-# LANGUAGE TypeFamilies #-}
54{-# LANGUAGE FlexibleInstances #-}
65{-# LANGUAGE GeneralizedNewtypeDeriving #-}
76{-# LANGUAGE DeriveTraversable #-}
87{-# LANGUAGE DeriveDataTypeable #-}
9−{-# LANGUAGE StandaloneDeriving #-}
108
119-- | This module provides a 'Data.Map' variant which uses the value's
1210-- 'Monoid' instance to accumulate conflicting entries when merging
@@ -18,7 +16,7 @@
1816-- underlying 'Map'.
1917
2018module Data.Map.Monoidal
21− ( MonoidalMap(..)
19+ ( MonoidalMap
2220 -- * Often-needed functions
2321 , singleton
2422 , size
@@ -28,110 +26,9 @@ module Data.Map.Monoidal
2826 , assocs
2927 , elems
3028 , keys
31− , (!)
32− , (\\)
33− , adjust
34− , adjustWithKey
35− , alter
36− , delete
37− , deleteAt
38− , deleteFindMax
39− , deleteFindMin
40− , deleteMax
41− , deleteMin
42− , difference
43− , differenceWith
44− , differenceWithKey
45− , elemAt
46− , empty
47− , filter
48− , filterWithKey
49− , findIndex
50− , findMax
51− , findMin
52− , foldMapWithKey
53− , foldl
54− , foldl'
55− , foldlWithKey
56− , foldlWithKey'
57− , foldr
58− , foldr'
59− , foldrWithKey
60− , foldrWithKey'
61− , fromAscList
62− , fromAscListWith
63− , fromAscListWithKey
64− , fromDistinctAscList
65− , fromDistinctList
66− , fromList
67− , fromListWith
68− , fromListWithKey
69− , fromSet
70− , insert
71− , insertLookupWithKey
72− , insertWith
73− , insertWithKey
74− , intersectionWith
75− , intersectionWithKey
76− , isProperSubmapOf
77− , isProperSubmapOfBy
78− , isSubmapOf
79− , isSubmapOfBy
80− , keysSet
81− , lookup
82− , lookupGE
83− , lookupGT
84− , lookupIndex
85− , lookupLE
86− , lookupLT
87− , map
88− , mapAccum
89− , mapAccumRWithKey
90− , mapAccumWithKey
91− , mapEither
92− , mapEitherWithKey
93− , mapKeys
94− , mapKeysMonotonic
95− , mapKeysWith
96− , mapMaybe
97− , mapMaybeWithKey
98− , mapWithKey
99− , maxView
100− , maxViewWithKey
101− , mergeWithKey
102− , minView
103− , minViewWithKey
104− , null
105− , partition
106− , partitionWithKey
107− , split
108− , splitLookup
109− , splitRoot
110− , toAscList
111− , toDescList
112− , toList
113− , traverseWithKey
114− , unionWith
115− , unionWithKey
116− , unionsWith
117− , update
118− , updateAt
119− , updateLookupWithKey
120− , updateMax
121− , updateMaxWithKey
122− , updateMin
123− , updateMinWithKey
124− , updateWithKey
125− , valid
126− -- , showTree
127− -- , showTreeWith
12829 ) where
12930
130−import Prelude hiding (null, lookup, map, foldl, foldr, filter)
131−
132−import Data.Coerce (coerce)
133−import Data.Set (Set)
134−import Data.Semigroup
31+import Data.Monoid
13532import Data.Foldable (Foldable)
13633import Data.Traversable (Traversable)
13734import Control.Applicative (Applicative, pure)
@@ -139,80 +36,52 @@ import Data.Data (Data)
13936import Data.Typeable (Typeable)
14037
14138#if MIN_VERSION_base(4,7,0)
142−import qualified GHC.Exts as IsList
39+import GHC.Exts (IsList(..))
14340#endif
14441
14542import Control.DeepSeq
14643import qualified Data.Map as M
14744import Control.Lens
14845import Control.Newtype
149−import Data.Aeson(FromJSON, ToJSON, FromJSON1, ToJSON1)
150−#if MIN_VERSION_containers(0,5,9)
151−import Data.Functor.Classes
152−#endif
153−import Data.Align
154−#ifdef MIN_VERSION_semialign
155−import Data.Semialign (Unalign)
156−#if MIN_VERSION_semialign(1,1,0)
157−import Data.Zip (Zip)
158−#endif
159−#endif
16046
16147-- | A 'Map' with monoidal accumulation
162−newtype MonoidalMap k a = MonoidalMap { getMonoidalMap :: M.Map k a }
163− deriving ( Show, Read, Functor, Eq, Ord, NFData
164− , Foldable, Traversable
165− , FromJSON, ToJSON, FromJSON1, ToJSON1
166− , Data, Typeable, Align
167−#if MIN_VERSION_these(0,8,0)
168− , Semialign
169−#endif
170−#ifdef MIN_VERSION_semialign
171− , Unalign
172−#if MIN_VERSION_semialign(1,1,0)
173− , Zip
174−#endif
175−#endif
176− )
177−
178−#if MIN_VERSION_containers(0,5,9)
179−deriving instance (Ord k) => Eq1 (MonoidalMap k)
180−deriving instance (Ord k) => Ord1 (MonoidalMap k)
181−deriving instance (Show k) => Show1 (MonoidalMap k)
182−#endif
48+newtype MonoidalMap k a = MM (M.Map k a)
49+ deriving (Show, Read, Functor, Eq, Ord, NFData,
50+ Foldable, Traversable,
51+ Data, Typeable)
18352
18453type instance Index (MonoidalMap k a) = k
18554type instance IxValue (MonoidalMap k a) = a
18655instance Ord k => Ixed (MonoidalMap k a) where
187− ix k f (MonoidalMap m) = case M.lookup k m of
188− Just v -> f v <&> \v' -> MonoidalMap (M.insert k v' m)
189− Nothing -> pure (MonoidalMap m)
56+ ix k f (MM m) = case M.lookup k m of
57+ Just v -> f v <&> \v' -> MM (M.insert k v' m)
58+ Nothing -> pure (MM m)
19059 {-# INLINE ix #-}
19160
19261instance Ord k => At (MonoidalMap k a) where
193− at k f (MonoidalMap m) = f mv <&> \r -> case r of
194− Nothing -> maybe (MonoidalMap m) (const (MonoidalMap $ M.delete k m)) mv
195− Just v' -> MonoidalMap $ M.insert k v' m
62+ at k f (MM m) = f mv <&> \r -> case r of
63+ Nothing -> maybe (MM m) (const (MM $ M.delete k m)) mv
64+ Just v' -> MM $ M.insert k v' m
19665 where mv = M.lookup k m
19766 {-# INLINE at #-}
19867
19968instance Each (MonoidalMap k a) (MonoidalMap k b) a b
20069
201−instance FunctorWithIndex k (MonoidalMap k)
202−instance FoldableWithIndex k (MonoidalMap k)
203−instance TraversableWithIndex k (MonoidalMap k) where
204− itraverse f (MonoidalMap m) = fmap MonoidalMap $ itraverse f m
70+instance Ord k => FunctorWithIndex k (MonoidalMap k)
71+instance Ord k => FoldableWithIndex k (MonoidalMap k)
72+instance Ord k => TraversableWithIndex k (MonoidalMap k) where
73+ itraverse f (MM m) = fmap MM $ itraverse f m
20574 {-# INLINE itraverse #-}
20675
20776instance Ord k => TraverseMin k (MonoidalMap k) where
208− traverseMin f (MonoidalMap m) = fmap MonoidalMap $ traverseMin f m
77+ traverseMin f (MM m) = fmap MM $ traverseMin f m
20978 {-# INLINE traverseMin #-}
21079instance Ord k => TraverseMax k (MonoidalMap k) where
211− traverseMax f (MonoidalMap m) = fmap MonoidalMap $ traverseMax f m
80+ traverseMax f (MM m) = fmap MM $ traverseMax f m
21281 {-# INLINE traverseMax #-}
21382
21483instance AsEmpty (MonoidalMap k a) where
215− _Empty = nearly (MonoidalMap M.empty) (M.null . unpack)
84+ _Empty = nearly (MM M.empty) (M.null . unpack)
21685 {-# INLINE _Empty #-}
21786
21887instance Wrapped (MonoidalMap k a) where
@@ -220,36 +89,30 @@ instance Wrapped (MonoidalMap k a) where
22089 _Wrapped' = iso unpack pack
22190 {-# INLINE _Wrapped' #-}
22291
223−instance (Ord k, Semigroup a) => Semigroup (MonoidalMap k a) where
224− MonoidalMap a <> MonoidalMap b = MonoidalMap $ M.unionWith (<>) a b
225− {-# INLINE (<>) #-}
226−
227−instance (Ord k, Semigroup a) => Monoid (MonoidalMap k a) where
228− mempty = MonoidalMap mempty
92+instance (Ord k, Monoid a) => Monoid (MonoidalMap k a) where
93+ mempty = MM mempty
22994 {-# INLINE mempty #-}
230−#if !(MIN_VERSION_base(4,11,0))
231− mappend (MonoidalMap a) (MonoidalMap b) = MonoidalMap $ M.unionWith (<>) a b
95+ MM a `mappend` MM b = MM $ M.unionWith mappend a b
23296 {-# INLINE mappend #-}
233−#endif
23497
23598instance Newtype (MonoidalMap k a) (M.Map k a) where
236− pack = MonoidalMap
99+ pack = MM
237100 {-# INLINE pack #-}
238− unpack (MonoidalMap a) = a
101+ unpack (MM a) = a
239102 {-# INLINE unpack #-}
240103
241104#if MIN_VERSION_base(4,7,0)
242−instance (Ord k, Semigroup a) => IsList.IsList (MonoidalMap k a) where
105+instance (Ord k, Monoid a) => IsList (MonoidalMap k a) where
243106 type Item (MonoidalMap k a) = (k, a)
244− fromList = MonoidalMap . M.fromListWith (<>)
107+ fromList = MM . M.fromListWith mappend
245108 {-# INLINE fromList #-}
246109 toList = M.toList . unpack
247110 {-# INLINE toList #-}
248111#endif
249112
250113-- | /O(1)/. A map with a single element.
251−singleton :: k -> a -> MonoidalMap k a
252−singleton k a = MonoidalMap $ M.singleton k a
114+singleton :: Ord k => k -> a -> MonoidalMap k a
115+singleton k a = MM $ M.singleton k a
253116{-# INLINE singleton #-}
254117
255118-- | /O(1)/. The number of elements in the map.
@@ -277,7 +140,7 @@ findWithDefault def k = M.findWithDefault def k . unpack
277140-- | /O(log n)/. Delete a key and its value from the map. When the key is not
278141-- a member of the map, the original map is returned.
279142delete :: Ord k => k -> MonoidalMap k a -> MonoidalMap k a
280−delete k = _Wrapping' MonoidalMap %~ M.delete k
143+delete k = _Wrapping' MM %~ M.delete k
281144{-# INLINE delete #-}
282145
283146-- | /O(n)/. Return all elements of the map and their keys
@@ -296,409 +159,3 @@ elems = M.elems . unpack
296159keys :: MonoidalMap k a -> [k]
297160keys = M.keys . unpack
298161{-# INLINE keys #-}
299−
300−
301−
302−(!) :: forall k a. Ord k => MonoidalMap k a -> k -> a
303−(!) = coerce ((M.!) :: M.Map k a -> k -> a)
304−infixl 9 !
305−
306−(\\) :: forall k a b. Ord k => MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k a
307−(\\) = coerce ((M.\\) :: M.Map k a -> M.Map k b -> M.Map k a)
308−infixl 9 \\ --
309−
310−null :: forall k a. MonoidalMap k a -> Bool
311−null = coerce (M.null :: M.Map k a -> Bool)
312−{-# INLINE null #-}
313−
314−lookup :: forall k a. Ord k => k -> MonoidalMap k a -> Maybe a
315−lookup = coerce (M.lookup :: k -> M.Map k a -> Maybe a)
316−{-# INLINE lookup #-}
317−
318−lookupLT :: forall k a. Ord k => k -> MonoidalMap k a -> Maybe (k, a)
319−lookupLT = coerce (M.lookupLT :: k -> M.Map k a -> Maybe (k,a))
320−{-# INLINE lookupLT #-}
321−
322−lookupGT :: forall k a. Ord k => k -> MonoidalMap k a -> Maybe (k, a)
323−lookupGT = coerce (M.lookupGT :: k -> M.Map k a -> Maybe (k,a))
324−{-# INLINE lookupGT #-}
325−
326−lookupLE :: forall k a. Ord k => k -> MonoidalMap k a -> Maybe (k, a)
327−lookupLE = coerce (M.lookupLE :: k -> M.Map k a -> Maybe (k,a))
328−{-# INLINE lookupLE #-}
329−
330−lookupGE :: forall k a. Ord k => k -> MonoidalMap k a -> Maybe (k, a)
331−lookupGE = coerce (M.lookupGE :: k -> M.Map k a -> Maybe (k,a))
332−{-# INLINE lookupGE #-}
333−
334−empty :: forall k a. MonoidalMap k a
335−empty = coerce (M.empty :: M.Map k a)
336−{-# INLINE empty #-}
337−
338−insert :: forall k a. Ord k => k -> a -> MonoidalMap k a -> MonoidalMap k a
339−insert = coerce (M.insert :: k -> a -> M.Map k a -> M.Map k a)
340−{-# INLINE insert #-}
341−
342−insertWith :: forall k a. Ord k => (a -> a -> a) -> k -> a -> MonoidalMap k a -> MonoidalMap k a
343−insertWith = coerce (M.insertWith :: (a -> a -> a) -> k -> a -> M.Map k a -> M.Map k a)
344−{-# INLINE insertWith #-}
345−
346−insertWithKey :: forall k a. Ord k => (k -> a -> a -> a) -> k -> a -> MonoidalMap k a -> MonoidalMap k a
347−insertWithKey = coerce (M.insertWithKey :: (k -> a -> a -> a) -> k -> a -> M.Map k a -> M.Map k a)
348−{-# INLINE insertWithKey #-}
349−
350−insertLookupWithKey :: forall k a. Ord k => (k -> a -> a -> a) -> k -> a -> MonoidalMap k a -> (Maybe a, MonoidalMap k a)
351−insertLookupWithKey = coerce (M.insertLookupWithKey :: (k -> a -> a -> a) -> k -> a -> M.Map k a -> (Maybe a, M.Map k a))
352−{-# INLINE insertLookupWithKey #-}
353−
354−adjust :: forall k a. Ord k => (a -> a) -> k -> MonoidalMap k a -> MonoidalMap k a
355−adjust = coerce (M.adjust :: (a -> a) -> k -> M.Map k a -> M.Map k a)
356−{-# INLINE adjust #-}
357−
358−adjustWithKey :: forall k a. Ord k => (k -> a -> a) -> k -> MonoidalMap k a -> MonoidalMap k a
359−adjustWithKey = coerce (M.adjustWithKey :: (k -> a -> a) -> k -> M.Map k a -> M.Map k a)
360−{-# INLINE adjustWithKey #-}
361−
362−update :: forall k a. Ord k => (a -> Maybe a) -> k -> MonoidalMap k a -> MonoidalMap k a
363−update = coerce (M.update :: (a -> Maybe a) -> k -> M.Map k a -> M.Map k a)
364−{-# INLINE update #-}
365−
366−updateWithKey :: forall k a. Ord k => (k -> a -> Maybe a) -> k -> MonoidalMap k a -> MonoidalMap k a
367−updateWithKey = coerce (M.updateWithKey :: (k -> a -> Maybe a) -> k -> M.Map k a -> M.Map k a)
368−{-# INLINE updateWithKey #-}
369−
370−updateLookupWithKey :: forall k a. Ord k => (k -> a -> Maybe a) -> k -> MonoidalMap k a -> (Maybe a, MonoidalMap k a)
371−updateLookupWithKey = coerce (M.updateLookupWithKey :: (k -> a -> Maybe a) -> k -> M.Map k a -> (Maybe a, M.Map k a))
372−{-# INLINE updateLookupWithKey #-}
373−
374−alter :: forall k a. Ord k => (Maybe a -> Maybe a) -> k -> MonoidalMap k a -> MonoidalMap k a
375−alter = coerce (M.alter :: (Maybe a -> Maybe a) -> k -> M.Map k a -> M.Map k a)
376−{-# INLINE alter #-}
377−
378−unionWith :: forall k a. Ord k => (a -> a -> a) -> MonoidalMap k a -> MonoidalMap k a -> MonoidalMap k a
379−unionWith = coerce (M.unionWith :: (a -> a -> a) -> M.Map k a -> M.Map k a -> M.Map k a)
380−{-# INLINE unionWith #-}
381−
382−unionWithKey :: forall k a. Ord k => (k -> a -> a -> a) -> MonoidalMap k a -> MonoidalMap k a -> MonoidalMap k a
383−unionWithKey = coerce (M.unionWithKey :: (k -> a -> a -> a) -> M.Map k a -> M.Map k a -> M.Map k a)
384−{-# INLINE unionWithKey #-}
385−
386−unionsWith :: forall k a. Ord k => (a -> a -> a) -> [MonoidalMap k a] -> MonoidalMap k a
387−unionsWith = coerce (M.unionsWith :: (a -> a -> a) -> [M.Map k a] -> M.Map k a)
388−{-# INLINE unionsWith #-}
389−
390−difference :: forall k a b. Ord k => MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k a
391−difference = (\\)
392−{-# INLINE difference #-}
393−
394−differenceWith :: forall k a b. Ord k => (a -> b -> Maybe a) -> MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k a
395−differenceWith = coerce (M.differenceWith :: (a -> b -> Maybe a) -> M.Map k a -> M.Map k b -> M.Map k a)
396−{-# INLINE differenceWith #-}
397−
398−differenceWithKey :: forall k a b. Ord k => (k -> a -> b -> Maybe a) -> MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k a
399−differenceWithKey = coerce (M.differenceWithKey :: (k -> a -> b -> Maybe a) -> M.Map k a -> M.Map k b -> M.Map k a)
400−{-# INLINE differenceWithKey #-}
401−
402−intersectionWith :: forall k a b c. Ord k => (a -> b -> c) -> MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k c
403−intersectionWith = coerce (M.intersectionWith :: (a -> b -> c) -> M.Map k a -> M.Map k b -> M.Map k c)
404−{-# INLINE intersectionWith #-}
405−
406−intersectionWithKey :: forall k a b c. Ord k => (k -> a -> b -> c) -> MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k c
407−intersectionWithKey = coerce (M.intersectionWithKey :: (k -> a -> b -> c) -> M.Map k a -> M.Map k b -> M.Map k c)
408−{-# INLINE intersectionWithKey #-}
409−
410−mergeWithKey :: forall k a b c. Ord k => (k -> a -> b -> Maybe c) -> (MonoidalMap k a -> MonoidalMap k c) -> (MonoidalMap k b -> MonoidalMap k c) -> MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k c
411−mergeWithKey = coerce (M.mergeWithKey :: (k -> a -> b -> Maybe c) -> (M.Map k a -> M.Map k c) -> (M.Map k b -> M.Map k c) -> M.Map k a -> M.Map k b -> M.Map k c)
412−{-# INLINE mergeWithKey #-}
413−
414−map :: (a -> b) -> MonoidalMap k a -> MonoidalMap k b
415−map = fmap
416−{-# INLINE map #-}
417−
418−mapWithKey :: forall k a b. (k -> a -> b) -> MonoidalMap k a -> MonoidalMap k b
419−mapWithKey = coerce (M.mapWithKey :: (k -> a -> b) -> M.Map k a -> M.Map k b)
420−{-# INLINE mapWithKey #-}
421−
422−traverseWithKey :: Applicative t => (k -> a -> t b) -> MonoidalMap k a -> t (MonoidalMap k b)
423−traverseWithKey = itraverse
424−{-# INLINE traverseWithKey #-}
425−
426−mapAccum :: forall k a b c. (a -> b -> (a, c)) -> a -> MonoidalMap k b -> (a, MonoidalMap k c)
427−mapAccum = coerce (M.mapAccum :: (a -> b -> (a, c)) -> a -> M.Map k b -> (a, M.Map k c))
428−{-# INLINE mapAccum #-}
429−
430−mapAccumWithKey :: forall k a b c. (a -> k -> b -> (a, c)) -> a -> MonoidalMap k b -> (a, MonoidalMap k c)
431−mapAccumWithKey = coerce (M.mapAccumWithKey :: (a -> k -> b -> (a, c)) -> a -> M.Map k b -> (a, M.Map k c))
432−{-# INLINE mapAccumWithKey #-}
433−
434−mapAccumRWithKey :: forall k a b c. (a -> k -> b -> (a, c)) -> a -> MonoidalMap k b -> (a, MonoidalMap k c)
435−mapAccumRWithKey = coerce (M.mapAccumRWithKey :: (a -> k -> b -> (a, c)) -> a -> M.Map k b -> (a, M.Map k c))
436−{-# INLINE mapAccumRWithKey #-}
437−
438−mapKeys :: forall k1 k2 a. Ord k2 => (k1 -> k2) -> MonoidalMap k1 a -> MonoidalMap k2 a
439−mapKeys = coerce (M.mapKeys :: (k1 -> k2) -> M.Map k1 a -> M.Map k2 a)
440−{-# INLINE mapKeys #-}
441−
442−mapKeysWith :: forall k1 k2 a. Ord k2 => (a -> a -> a) -> (k1 -> k2) -> MonoidalMap k1 a -> MonoidalMap k2 a
443−mapKeysWith = coerce (M.mapKeysWith :: (a -> a -> a) -> (k1 -> k2) -> M.Map k1 a -> M.Map k2 a)
444−{-# INLINE mapKeysWith #-}
445−
446−-- | /O(n)/.
447−-- @'mapKeysMonotonic' f s == 'mapKeys' f s@, but works only when @f@
448−-- is strictly increasing (both monotonic and injective).
449−-- That is, for any values @x@ and @y@, if @x@ < @y@ then @f x@ < @f y@
450−-- and @f@ is injective (i.e. it never maps two input keys to the same output key).
451−-- /The precondition is not checked./
452−-- Semi-formally, we have:
453−--
454−-- > and [x < y ==> f x < f y | x <- ls, y <- ls]
455−-- > ==> mapKeysMonotonic f s == mapKeys f s
456−-- > where ls = keys s
457−--
458−-- This means that @f@ maps distinct original keys to distinct resulting keys.
459−-- This function has better performance than 'mapKeys'.
460−--
461−-- > mapKeysMonotonic (\ k -> k * 2) (fromList [(5,"a"), (3,"b")]) == fromList [(6, "b"), (10, "a")]
462−-- > valid (mapKeysMonotonic (\ k -> k * 2) (fromList [(5,"a"), (3,"b")])) == True
463−-- > valid (mapKeysMonotonic (\ _ -> 1) (fromList [(5,"a"), (3,"b")])) == False
464−mapKeysMonotonic :: forall k1 k2 a. (k1 -> k2) -> MonoidalMap k1 a -> MonoidalMap k2 a
465−mapKeysMonotonic = coerce (M.mapKeysMonotonic :: (k1 -> k2) -> M.Map k1 a -> M.Map k2 a)
466−{-# INLINE mapKeysMonotonic #-}
467−
468−foldr :: forall k a b. (a -> b -> b) -> b -> MonoidalMap k a -> b
469−foldr = coerce (M.foldr :: (a -> b -> b) -> b -> M.Map k a -> b)
470−{-# INLINE foldr #-}
471−
472−foldl :: forall k a b. (a -> b -> a) -> a -> MonoidalMap k b -> a
473−foldl = coerce (M.foldl :: (a -> b -> a) -> a -> M.Map k b -> a)
474−{-# INLINE foldl #-}
475−
476−foldrWithKey :: forall k a b. (k -> a -> b -> b) -> b -> MonoidalMap k a -> b
477−foldrWithKey = coerce (M.foldrWithKey :: (k -> a -> b -> b) -> b -> M.Map k a -> b)
478−{-# INLINE foldrWithKey #-}
479−
480−foldlWithKey :: forall k a b. (a -> k -> b -> a) -> a -> MonoidalMap k b -> a
481−foldlWithKey = coerce (M.foldlWithKey :: (a -> k -> b -> a) -> a -> M.Map k b -> a)
482−{-# INLINE foldlWithKey #-}
483−
484−foldMapWithKey :: forall k a m. Monoid m => (k -> a -> m) -> MonoidalMap k a -> m
485−foldMapWithKey = coerce (M.foldMapWithKey :: Monoid m => (k -> a -> m) -> M.Map k a -> m)
486−{-# INLINE foldMapWithKey #-}
487−
488−foldr' :: forall k a b. (a -> b -> b) -> b -> MonoidalMap k a -> b
489−foldr' = coerce (M.foldr' :: (a -> b -> b) -> b -> M.Map k a -> b)
490−{-# INLINE foldr' #-}
491−
492−foldl' :: forall k a b. (a -> b -> a) -> a -> MonoidalMap k b -> a
493−foldl' = coerce (M.foldl' :: (a -> b -> a) -> a -> M.Map k b -> a)
494−{-# INLINE foldl' #-}
495−
496−foldrWithKey' :: forall k a b. (k -> a -> b -> b) -> b -> MonoidalMap k a -> b
497−foldrWithKey' = coerce (M.foldrWithKey' :: (k -> a -> b -> b) -> b -> M.Map k a -> b)
498−{-# INLINE foldrWithKey' #-}
499−
500−foldlWithKey' :: forall k a b. (a -> k -> b -> a) -> a -> MonoidalMap k b -> a
501−foldlWithKey' = coerce (M.foldlWithKey' :: (a -> k -> b -> a) -> a -> M.Map k b -> a)
502−{-# INLINE foldlWithKey' #-}
503−
504−keysSet :: forall k a. MonoidalMap k a -> Set k
505−keysSet = coerce (M.keysSet :: M.Map k a -> Set k)
506−{-# INLINE keysSet #-}
507−
508−fromSet :: forall k a. (k -> a) -> Set k -> MonoidalMap k a
509−fromSet = coerce (M.fromSet :: (k -> a) -> Set k -> M.Map k a)
510−{-# INLINE fromSet #-}
511−
512−toList :: forall k a. MonoidalMap k a -> [(k, a)]
513−toList = coerce (M.toList :: M.Map k a -> [(k, a)])
514−{-# INLINE toList #-}
515−
516−fromList :: forall k a. Ord k => [(k, a)] -> MonoidalMap k a
517−fromList = coerce (M.fromList :: [(k, a)] -> M.Map k a)
518−{-# INLINE fromList #-}
519−
520−fromListWith :: forall k a. Ord k => (a -> a -> a) -> [(k, a)] -> MonoidalMap k a
521−fromListWith = coerce (M.fromListWith :: (a -> a -> a) -> [(k, a)] -> M.Map k a)
522−{-# INLINE fromListWith #-}
523−
524−fromListWithKey :: forall k a. Ord k => (k -> a -> a -> a) -> [(k, a)] -> MonoidalMap k a
525−fromListWithKey = coerce (M.fromListWithKey :: (k -> a -> a -> a) -> [(k, a)] -> M.Map k a)
526−{-# INLINE fromListWithKey #-}
527−
528−toAscList :: forall k a. MonoidalMap k a -> [(k, a)]
529−toAscList = coerce (M.toAscList :: M.Map k a -> [(k, a)])
530−{-# INLINE toAscList #-}
531−
532−toDescList :: forall k a. MonoidalMap k a -> [(k, a)]
533−toDescList = coerce (M.toDescList :: M.Map k a -> [(k, a)])
534−{-# INLINE toDescList #-}
535−
536−fromAscList :: forall k a. Eq k => [(k, a)] -> MonoidalMap k a
537−fromAscList = coerce (M.fromAscList :: [(k, a)] -> M.Map k a)
538−{-# INLINE fromAscList #-}
539−
540−fromAscListWith :: forall k a. Eq k => (a -> a -> a) -> [(k, a)] -> MonoidalMap k a
541−fromAscListWith = coerce (M.fromAscListWith :: (a -> a -> a) -> [(k, a)] -> M.Map k a)
542−{-# INLINE fromAscListWith #-}
543−
544−fromAscListWithKey :: forall k a. Eq k => (k -> a -> a -> a) -> [(k, a)] -> MonoidalMap k a
545−fromAscListWithKey = coerce (M.fromAscListWithKey :: (k -> a -> a -> a) -> [(k, a)] -> M.Map k a)
546−{-# INLINE fromAscListWithKey #-}
547−
548−fromDistinctAscList :: forall k a. [(k, a)] -> MonoidalMap k a
549−fromDistinctAscList = coerce (M.fromDistinctAscList :: [(k, a)] -> M.Map k a)
550−{-# INLINE fromDistinctAscList #-}
551−
552−fromDistinctList :: forall k a. Ord k => [(k, a)] -> MonoidalMap k a
553−fromDistinctList = coerce (M.fromList :: [(k, a)] -> M.Map k a)
554−{-# INLINE fromDistinctList #-}
555−
556−filter :: forall k a. (a -> Bool) -> MonoidalMap k a -> MonoidalMap k a
557−filter = coerce (M.filter :: (a -> Bool) -> M.Map k a -> M.Map k a)
558−{-# INLINE filter #-}
559−
560−filterWithKey :: forall k a. (k -> a -> Bool) -> MonoidalMap k a -> MonoidalMap k a
561−filterWithKey = coerce (M.filterWithKey :: (k -> a -> Bool) -> M.Map k a -> M.Map k a)
562−{-# INLINE filterWithKey #-}
563−
564−partition :: forall k a. (a -> Bool) -> MonoidalMap k a -> (MonoidalMap k a, MonoidalMap k a)
565−partition = coerce (M.partition :: (a -> Bool) -> M.Map k a -> (M.Map k a, M.Map k a))
566−{-# INLINE partition #-}
567−
568−partitionWithKey :: forall k a. (k -> a -> Bool) -> MonoidalMap k a -> (MonoidalMap k a, MonoidalMap k a)
569−partitionWithKey = coerce (M.partitionWithKey :: (k -> a -> Bool) -> M.Map k a -> (M.Map k a, M.Map k a))
570−{-# INLINE partitionWithKey #-}
571−
572−mapMaybe :: forall k a b. (a -> Maybe b) -> MonoidalMap k a -> MonoidalMap k b
573−mapMaybe = coerce (M.mapMaybe :: (a -> Maybe b) -> M.Map k a -> M.Map k b)
574−{-# INLINE mapMaybe #-}
575−
576−mapMaybeWithKey :: forall k a b. (k -> a -> Maybe b) -> MonoidalMap k a -> MonoidalMap k b
577−mapMaybeWithKey = coerce (M.mapMaybeWithKey :: (k -> a -> Maybe b) -> M.Map k a -> M.Map k b)
578−{-# INLINE mapMaybeWithKey #-}
579−
580−mapEither :: forall k a b c. (a -> Either b c) -> MonoidalMap k a -> (MonoidalMap k b, MonoidalMap k c)
581−mapEither = coerce (M.mapEither :: (a -> Either b c) -> M.Map k a -> (M.Map k b, M.Map k c))
582−{-# INLINE mapEither #-}
583−
584−mapEitherWithKey :: forall k a b c. (k -> a -> Either b c) -> MonoidalMap k a -> (MonoidalMap k b, MonoidalMap k c)
585−mapEitherWithKey = coerce (M.mapEitherWithKey :: (k -> a -> Either b c) -> M.Map k a -> (M.Map k b, M.Map k c))
586−{-# INLINE mapEitherWithKey #-}
587−
588−split :: forall k a. Ord k => k -> MonoidalMap k a -> (MonoidalMap k a, MonoidalMap k a)
589−split = coerce (M.split :: k -> M.Map k a -> (M.Map k a, M.Map k a))
590−{-# INLINE split #-}
591−
592−splitLookup :: forall k a. Ord k => k -> MonoidalMap k a -> (MonoidalMap k a, Maybe a, MonoidalMap k a)
593−splitLookup = coerce (M.splitLookup :: k -> M.Map k a -> (M.Map k a, Maybe a, M.Map k a))
594−{-# INLINE splitLookup #-}
595−
596−splitRoot :: forall k a. MonoidalMap k a -> [MonoidalMap k a]
597−splitRoot = coerce (M.splitRoot :: M.Map k a -> [M.Map k a])
598−{-# INLINE splitRoot #-}
599−
600−isSubmapOf :: forall k a. (Ord k, Eq a) => MonoidalMap k a -> MonoidalMap k a -> Bool
601−isSubmapOf = coerce (M.isSubmapOf :: M.Map k a -> M.Map k a -> Bool)
602−{-# INLINE isSubmapOf #-}
603−
604−isSubmapOfBy :: forall k a b. Ord k => (a -> b -> Bool) -> MonoidalMap k a -> MonoidalMap k b -> Bool
605−isSubmapOfBy = coerce (M.isSubmapOfBy :: (a -> b -> Bool) -> M.Map k a -> M.Map k b -> Bool)
606−{-# INLINE isSubmapOfBy #-}
607−
608−isProperSubmapOf :: forall k a. (Ord k, Eq a) => MonoidalMap k a -> MonoidalMap k a -> Bool
609−isProperSubmapOf = coerce (M.isProperSubmapOf :: M.Map k a -> M.Map k a -> Bool)
610−{-# INLINE isProperSubmapOf #-}
611−
612−isProperSubmapOfBy :: forall k a b. Ord k => (a -> b -> Bool) -> MonoidalMap k a -> MonoidalMap k b -> Bool
613−isProperSubmapOfBy = coerce (M.isProperSubmapOfBy :: (a -> b -> Bool) -> M.Map k a -> M.Map k b -> Bool)
614−{-# INLINE isProperSubmapOfBy #-}
615−
616−lookupIndex :: forall k a. Ord k => k -> MonoidalMap k a -> Maybe Int
617−lookupIndex = coerce (M.lookupIndex :: k -> M.Map k a -> Maybe Int)
618−{-# INLINE lookupIndex #-}
619−
620−findIndex :: forall k a. Ord k => k -> MonoidalMap k a -> Int
621−findIndex = coerce (M.findIndex :: k -> M.Map k a -> Int)
622−{-# INLINE findIndex #-}
623−
624−elemAt :: forall k a. Int -> MonoidalMap k a -> (k, a)
625−elemAt = coerce (M.elemAt :: Int -> M.Map k a -> (k, a))
626−{-# INLINE elemAt #-}
627−
628−updateAt :: forall k a. (k -> a -> Maybe a) -> Int -> MonoidalMap k a -> MonoidalMap k a
629−updateAt = coerce (M.updateAt :: (k -> a -> Maybe a) -> Int -> M.Map k a -> M.Map k a)
630−{-# INLINE updateAt #-}
631−
632−deleteAt :: forall k a. Int -> MonoidalMap k a -> MonoidalMap k a
633−deleteAt = coerce (M.deleteAt :: Int -> M.Map k a -> M.Map k a)
634−{-# INLINE deleteAt #-}
635−
636−findMin :: forall k a. MonoidalMap k a -> (k, a)
637−findMin = coerce (M.findMin :: M.Map k a -> (k, a))
638−{-# INLINE findMin #-}
639−
640−findMax :: forall k a. MonoidalMap k a -> (k, a)
641−findMax = coerce (M.findMax :: M.Map k a -> (k, a))
642−{-# INLINE findMax #-}
643−
644−deleteMin :: forall k a. MonoidalMap k a -> MonoidalMap k a
645−deleteMin = coerce (M.deleteMin :: M.Map k a -> M.Map k a)
646−{-# INLINE deleteMin #-}
647−
648−deleteMax :: forall k a. MonoidalMap k a -> MonoidalMap k a
649−deleteMax = coerce (M.deleteMax :: M.Map k a -> M.Map k a)
650−{-# INLINE deleteMax #-}
651−
652−deleteFindMin :: forall k a. MonoidalMap k a -> ((k, a), MonoidalMap k a)
653−deleteFindMin = coerce (M.deleteFindMin :: M.Map k a -> ((k, a), M.Map k a))
654−{-# INLINE deleteFindMin #-}
655−
656−deleteFindMax :: forall k a. MonoidalMap k a -> ((k, a), MonoidalMap k a)
657−deleteFindMax = coerce (M.deleteFindMax :: M.Map k a -> ((k, a), M.Map k a))
658−{-# INLINE deleteFindMax #-}
659−
660−updateMin :: forall k a. (a -> Maybe a) -> MonoidalMap k a -> MonoidalMap k a
661−updateMin = coerce (M.updateMin :: (a -> Maybe a) -> M.Map k a -> M.Map k a)
662−{-# INLINE updateMin #-}
663−
664−updateMax :: forall k a. (a -> Maybe a) -> MonoidalMap k a -> MonoidalMap k a
665−updateMax = coerce (M.updateMax :: (a -> Maybe a) -> M.Map k a -> M.Map k a)
666−{-# INLINE updateMax #-}
667−
668−updateMinWithKey :: forall k a. (k -> a -> Maybe a) -> MonoidalMap k a -> MonoidalMap k a
669−updateMinWithKey = coerce (M.updateMinWithKey :: (k -> a -> Maybe a) -> M.Map k a -> M.Map k a)
670−{-# INLINE updateMinWithKey #-}
671−
672−updateMaxWithKey :: forall k a. (k -> a -> Maybe a) -> MonoidalMap k a -> MonoidalMap k a
673−updateMaxWithKey = coerce (M.updateMaxWithKey :: (k -> a -> Maybe a) -> M.Map k a -> M.Map k a)
674−{-# INLINE updateMaxWithKey #-}
675−
676−minView :: forall k a. MonoidalMap k a -> Maybe (a, MonoidalMap k a)
677−minView = coerce (M.minView :: M.Map k a -> Maybe (a, M.Map k a))
678−{-# INLINE minView #-}
679−
680−maxView :: forall k a. MonoidalMap k a -> Maybe (a, MonoidalMap k a)
681−maxView = coerce (M.maxView :: M.Map k a -> Maybe (a, M.Map k a))
682−{-# INLINE maxView #-}
683−
684−minViewWithKey :: forall k a. MonoidalMap k a -> Maybe ((k, a), MonoidalMap k a)
685−minViewWithKey = coerce (M.minViewWithKey :: M.Map k a -> Maybe ((k, a), M.Map k a))
686−{-# INLINE minViewWithKey #-}
687−
688−maxViewWithKey :: forall k a. MonoidalMap k a -> Maybe ((k, a), MonoidalMap k a)
689−maxViewWithKey = coerce (M.maxViewWithKey :: M.Map k a -> Maybe ((k, a), M.Map k a))
690−{-# INLINE maxViewWithKey #-}
691−
692−-- showTree :: forall k a. (Show k, Show a) => MonoidalMap k a -> String
693−-- showTree = coerce (M.showTree :: (Show k, Show a) => M.Map k a -> String)
694−-- {-# INLINE showTree #-}
695−
696−-- showTreeWith :: forall k a. (k -> a -> String) -> Bool -> Bool -> MonoidalMap k a -> String
697−-- showTreeWith = coerce (M.showTreeWith :: (k -> a -> String) -> Bool -> Bool -> M.Map k a -> String)
698−-- {-# INLINE showTreeWith #-}
699−
700−valid :: forall k a. Ord k => MonoidalMap k a -> Bool
701−valid = coerce (M.valid :: Ord k => M.Map k a -> Bool)
702−{-# INLINE valid #-}
703−
704−