git.iko.soy/monoidal-containers
on master help sign in
Merge pull request #25 from danbornside/more-functions

add most Data.Map.Strict functions

commit0cdfc5ba817823722874db9f38b2091f1b0680dc authorBen Gamari <ben@smart-cactus.org> dateMon 1 Oct 2018, 14:43 (8 years ago) parent38b2aca0909c4d
5 files changed+1011−17
.gitignore+3 .travis.yml+1−4 monoidal-containers.cabal+2−1 src/Data/Map/Monoidal.hs+503−6 src/Data/Map/Monoidal/Strict.hs+502−6
.gitignore+3
@@ -1,2 +1,5 @@
11dist
2+dist-newstyle
23cabal.config
4+cabal.project.local
5+.ghc.environment.*
.travis.yml+1−4
@@ -2,7 +2,7 @@
22#
33# runghc make_travis_yml_2.hs 'monoidal-containers.cabal'
44#
5−# For more information, see https://github.com/hvr/multi-ghc-travis
5+# For more information, see https://github.com/haskell-CI/haskell-ci
66#
77language: c
88sudo: false
@@ -43,9 +43,6 @@ matrix:
4343 - compiler: "ghc-7.8.4"
4444 # env: TEST=--disable-tests BENCH=--disable-benchmarks
4545 addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.2,ghc-7.8.4], sources: [hvr-ghc]}}
46− - compiler: "ghc-7.6.3"
47− # env: TEST=--disable-tests BENCH=--disable-benchmarks
48− addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.2,ghc-7.6.3], sources: [hvr-ghc]}}
4946
5047 allow_failures:
5148 - compiler: "ghc-8.6.1"
monoidal-containers.cabal+2−1
@@ -24,7 +24,7 @@ category: Data
2424build-type: Simple
2525cabal-version: >=1.10
2626extra-source-files: Changelog.md
27−tested-with: GHC ==7.6.3, GHC ==7.8.4, GHC ==8.0.2, GHC ==8.2.2, GHC ==8.4.3, GHC ==8.6.1
27+tested-with: GHC ==7.8.4, GHC ==8.0.2, GHC ==8.2.2, GHC ==8.4.3, GHC ==8.6.1
2828
2929source-repository head
3030 type: git
@@ -40,6 +40,7 @@ library
4040 DeriveTraversable,
4141 DeriveDataTypeable
4242 build-depends: base >=4.5 && <4.12,
43+ aeson >=1.0 && <1.5,
4344 containers >=0.5 && <0.7,
4445 deepseq >=1.3 && <1.5,
4546 unordered-containers >= 0.2 && < 0.3,
src/Data/Map/Monoidal.hs+503−6
@@ -1,10 +1,12 @@
11{-# LANGUAGE CPP #-}
2+{-# LANGUAGE ScopedTypeVariables #-}
23{-# LANGUAGE MultiParamTypeClasses #-}
34{-# LANGUAGE TypeFamilies #-}
45{-# LANGUAGE FlexibleInstances #-}
56{-# LANGUAGE GeneralizedNewtypeDeriving #-}
67{-# LANGUAGE DeriveTraversable #-}
78{-# LANGUAGE DeriveDataTypeable #-}
9+{-# LANGUAGE StandaloneDeriving #-}
810
911-- | This module provides a 'Data.Map' variant which uses the value's
1012-- 'Monoid' instance to accumulate conflicting entries when merging
@@ -26,8 +28,108 @@ module Data.Map.Monoidal
2628 , assocs
2729 , elems
2830 , 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+ , fromList
66+ , fromListWith
67+ , fromListWithKey
68+ , fromSet
69+ , insert
70+ , insertLookupWithKey
71+ , insertWith
72+ , insertWithKey
73+ , intersectionWith
74+ , intersectionWithKey
75+ , isProperSubmapOf
76+ , isProperSubmapOfBy
77+ , isSubmapOf
78+ , isSubmapOfBy
79+ , keysSet
80+ , lookup
81+ , lookupGE
82+ , lookupGT
83+ , lookupIndex
84+ , lookupLE
85+ , lookupLT
86+ , map
87+ , mapAccum
88+ , mapAccumRWithKey
89+ , mapAccumWithKey
90+ , mapEither
91+ , mapEitherWithKey
92+ , mapKeys
93+ , mapKeysMonotonic
94+ , mapKeysWith
95+ , mapMaybe
96+ , mapMaybeWithKey
97+ , mapWithKey
98+ , maxView
99+ , maxViewWithKey
100+ , mergeWithKey
101+ , minView
102+ , minViewWithKey
103+ , null
104+ , partition
105+ , partitionWithKey
106+ , split
107+ , splitLookup
108+ , splitRoot
109+ , toAscList
110+ , toDescList
111+ , toList
112+ , traverseWithKey
113+ , unionWith
114+ , unionWithKey
115+ , unionsWith
116+ , update
117+ , updateAt
118+ , updateLookupWithKey
119+ , updateMax
120+ , updateMaxWithKey
121+ , updateMin
122+ , updateMinWithKey
123+ , updateWithKey
124+ , valid
125+ -- , showTree
126+ -- , showTreeWith
29127 ) where
30128
129+import Prelude hiding (null, lookup, map, foldl, foldr, filter)
130+
131+import Data.Coerce (coerce)
132+import Data.Set (Set)
31133import Data.Semigroup
32134import Data.Foldable (Foldable)
33135import Data.Traversable (Traversable)
@@ -36,20 +138,31 @@ import Data.Data (Data)
36138import Data.Typeable (Typeable)
37139
38140#if MIN_VERSION_base(4,7,0)
39−import GHC.Exts (IsList(..))
141+import qualified GHC.Exts as IsList
40142#endif
41143
42144import Control.DeepSeq
43145import qualified Data.Map as M
44146import Control.Lens
45147import Control.Newtype
148+import Data.Aeson(FromJSON, ToJSON, FromJSON1, ToJSON1)
149+#if MIN_VERSION_containers(0,5,9)
150+import Data.Functor.Classes
151+#endif
46152
47153-- | A 'Map' with monoidal accumulation
48154newtype MonoidalMap k a = MonoidalMap { getMonoidalMap :: M.Map k a }
49155 deriving (Show, Read, Functor, Eq, Ord, NFData,
50156 Foldable, Traversable,
157+ FromJSON, ToJSON, FromJSON1, ToJSON1,
51158 Data, Typeable)
52159
160+#if MIN_VERSION_containers(0,5,9)
161+deriving instance (Ord k) => Eq1 (MonoidalMap k)
162+deriving instance (Ord k) => Ord1 (MonoidalMap k)
163+deriving instance (Show k) => Show1 (MonoidalMap k)
164+#endif
165+
53166type instance Index (MonoidalMap k a) = k
54167type instance IxValue (MonoidalMap k a) = a
55168instance Ord k => Ixed (MonoidalMap k a) where
@@ -67,9 +180,9 @@ instance Ord k => At (MonoidalMap k a) where
67180
68181instance Each (MonoidalMap k a) (MonoidalMap k b) a b
69182
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
183+instance FunctorWithIndex k (MonoidalMap k)
184+instance FoldableWithIndex k (MonoidalMap k)
185+instance TraversableWithIndex k (MonoidalMap k) where
73186 itraverse f (MonoidalMap m) = fmap MonoidalMap $ itraverse f m
74187 {-# INLINE itraverse #-}
75188
@@ -108,7 +221,7 @@ instance Newtype (MonoidalMap k a) (M.Map k a) where
108221 {-# INLINE unpack #-}
109222
110223#if MIN_VERSION_base(4,7,0)
111−instance (Ord k, Semigroup a) => IsList (MonoidalMap k a) where
224+instance (Ord k, Semigroup a) => IsList.IsList (MonoidalMap k a) where
112225 type Item (MonoidalMap k a) = (k, a)
113226 fromList = MonoidalMap . M.fromListWith (<>)
114227 {-# INLINE fromList #-}
@@ -117,7 +230,7 @@ instance (Ord k, Semigroup a) => IsList (MonoidalMap k a) where
117230#endif
118231
119232-- | /O(1)/. A map with a single element.
120−singleton :: Ord k => k -> a -> MonoidalMap k a
233+singleton :: k -> a -> MonoidalMap k a
121234singleton k a = MonoidalMap $ M.singleton k a
122235{-# INLINE singleton #-}
123236
@@ -165,3 +278,387 @@ elems = M.elems . unpack
165278keys :: MonoidalMap k a -> [k]
166279keys = M.keys . unpack
167280{-# INLINE keys #-}
281+
282+
283+
284+(!) :: forall k a. Ord k => MonoidalMap k a -> k -> a
285+(!) = coerce ((M.!) :: M.Map k a -> k -> a)
286+infixl 9 !
287+
288+(\\) :: forall k a b. Ord k => MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k a
289+(\\) = coerce ((M.\\) :: M.Map k a -> M.Map k b -> M.Map k a)
290+infixl 9 \\ --
291+
292+null :: forall k a. MonoidalMap k a -> Bool
293+null = coerce (M.null :: M.Map k a -> Bool)
294+{-# INLINE null #-}
295+
296+lookup :: forall k a. Ord k => k -> MonoidalMap k a -> Maybe a
297+lookup = coerce (M.lookup :: k -> M.Map k a -> Maybe a)
298+{-# INLINE lookup #-}
299+
300+lookupLT :: forall k a. Ord k => k -> MonoidalMap k a -> Maybe (k, a)
301+lookupLT = coerce (M.lookupLT :: k -> M.Map k a -> Maybe (k,a))
302+{-# INLINE lookupLT #-}
303+
304+lookupGT :: forall k a. Ord k => k -> MonoidalMap k a -> Maybe (k, a)
305+lookupGT = coerce (M.lookupGT :: k -> M.Map k a -> Maybe (k,a))
306+{-# INLINE lookupGT #-}
307+
308+lookupLE :: forall k a. Ord k => k -> MonoidalMap k a -> Maybe (k, a)
309+lookupLE = coerce (M.lookupLE :: k -> M.Map k a -> Maybe (k,a))
310+{-# INLINE lookupLE #-}
311+
312+lookupGE :: forall k a. Ord k => k -> MonoidalMap k a -> Maybe (k, a)
313+lookupGE = coerce (M.lookupGE :: k -> M.Map k a -> Maybe (k,a))
314+{-# INLINE lookupGE #-}
315+
316+empty :: forall k a. MonoidalMap k a
317+empty = coerce (M.empty :: M.Map k a)
318+{-# INLINE empty #-}
319+
320+insert :: forall k a. Ord k => k -> a -> MonoidalMap k a -> MonoidalMap k a
321+insert = coerce (M.insert :: k -> a -> M.Map k a -> M.Map k a)
322+{-# INLINE insert #-}
323+
324+insertWith :: forall k a. Ord k => (a -> a -> a) -> k -> a -> MonoidalMap k a -> MonoidalMap k a
325+insertWith = coerce (M.insertWith :: (a -> a -> a) -> k -> a -> M.Map k a -> M.Map k a)
326+{-# INLINE insertWith #-}
327+
328+insertWithKey :: forall k a. Ord k => (k -> a -> a -> a) -> k -> a -> MonoidalMap k a -> MonoidalMap k a
329+insertWithKey = coerce (M.insertWithKey :: (k -> a -> a -> a) -> k -> a -> M.Map k a -> M.Map k a)
330+{-# INLINE insertWithKey #-}
331+
332+insertLookupWithKey :: forall k a. Ord k => (k -> a -> a -> a) -> k -> a -> MonoidalMap k a -> (Maybe a, MonoidalMap k a)
333+insertLookupWithKey = coerce (M.insertLookupWithKey :: (k -> a -> a -> a) -> k -> a -> M.Map k a -> (Maybe a, M.Map k a))
334+{-# INLINE insertLookupWithKey #-}
335+
336+adjust :: forall k a. Ord k => (a -> a) -> k -> MonoidalMap k a -> MonoidalMap k a
337+adjust = coerce (M.adjust :: (a -> a) -> k -> M.Map k a -> M.Map k a)
338+{-# INLINE adjust #-}
339+
340+adjustWithKey :: forall k a. Ord k => (k -> a -> a) -> k -> MonoidalMap k a -> MonoidalMap k a
341+adjustWithKey = coerce (M.adjustWithKey :: (k -> a -> a) -> k -> M.Map k a -> M.Map k a)
342+{-# INLINE adjustWithKey #-}
343+
344+update :: forall k a. Ord k => (a -> Maybe a) -> k -> MonoidalMap k a -> MonoidalMap k a
345+update = coerce (M.update :: (a -> Maybe a) -> k -> M.Map k a -> M.Map k a)
346+{-# INLINE update #-}
347+
348+updateWithKey :: forall k a. Ord k => (k -> a -> Maybe a) -> k -> MonoidalMap k a -> MonoidalMap k a
349+updateWithKey = coerce (M.updateWithKey :: (k -> a -> Maybe a) -> k -> M.Map k a -> M.Map k a)
350+{-# INLINE updateWithKey #-}
351+
352+updateLookupWithKey :: forall k a. Ord k => (k -> a -> Maybe a) -> k -> MonoidalMap k a -> (Maybe a, MonoidalMap k a)
353+updateLookupWithKey = coerce (M.updateLookupWithKey :: (k -> a -> Maybe a) -> k -> M.Map k a -> (Maybe a, M.Map k a))
354+{-# INLINE updateLookupWithKey #-}
355+
356+alter :: forall k a. Ord k => (Maybe a -> Maybe a) -> k -> MonoidalMap k a -> MonoidalMap k a
357+alter = coerce (M.alter :: (Maybe a -> Maybe a) -> k -> M.Map k a -> M.Map k a)
358+{-# INLINE alter #-}
359+
360+unionWith :: forall k a. Ord k => (a -> a -> a) -> MonoidalMap k a -> MonoidalMap k a -> MonoidalMap k a
361+unionWith = coerce (M.unionWith :: (a -> a -> a) -> M.Map k a -> M.Map k a -> M.Map k a)
362+{-# INLINE unionWith #-}
363+
364+unionWithKey :: forall k a. Ord k => (k -> a -> a -> a) -> MonoidalMap k a -> MonoidalMap k a -> MonoidalMap k a
365+unionWithKey = coerce (M.unionWithKey :: (k -> a -> a -> a) -> M.Map k a -> M.Map k a -> M.Map k a)
366+{-# INLINE unionWithKey #-}
367+
368+unionsWith :: forall k a. Ord k => (a -> a -> a) -> [MonoidalMap k a] -> MonoidalMap k a
369+unionsWith = coerce (M.unionsWith :: (a -> a -> a) -> [M.Map k a] -> M.Map k a)
370+{-# INLINE unionsWith #-}
371+
372+difference :: forall k a b. Ord k => MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k a
373+difference = (\\)
374+{-# INLINE difference #-}
375+
376+differenceWith :: forall k a b. Ord k => (a -> b -> Maybe a) -> MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k a
377+differenceWith = coerce (M.differenceWith :: (a -> b -> Maybe a) -> M.Map k a -> M.Map k b -> M.Map k a)
378+{-# INLINE differenceWith #-}
379+
380+differenceWithKey :: forall k a b. Ord k => (k -> a -> b -> Maybe a) -> MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k a
381+differenceWithKey = coerce (M.differenceWithKey :: (k -> a -> b -> Maybe a) -> M.Map k a -> M.Map k b -> M.Map k a)
382+{-# INLINE differenceWithKey #-}
383+
384+intersectionWith :: forall k a b c. Ord k => (a -> b -> c) -> MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k c
385+intersectionWith = coerce (M.intersectionWith :: (a -> b -> c) -> M.Map k a -> M.Map k b -> M.Map k c)
386+{-# INLINE intersectionWith #-}
387+
388+intersectionWithKey :: forall k a b c. Ord k => (k -> a -> b -> c) -> MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k c
389+intersectionWithKey = coerce (M.intersectionWithKey :: (k -> a -> b -> c) -> M.Map k a -> M.Map k b -> M.Map k c)
390+{-# INLINE intersectionWithKey #-}
391+
392+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
393+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)
394+{-# INLINE mergeWithKey #-}
395+
396+map :: (a -> b) -> MonoidalMap k a -> MonoidalMap k b
397+map = fmap
398+{-# INLINE map #-}
399+
400+mapWithKey :: forall k a b. (k -> a -> b) -> MonoidalMap k a -> MonoidalMap k b
401+mapWithKey = coerce (M.mapWithKey :: (k -> a -> b) -> M.Map k a -> M.Map k b)
402+{-# INLINE mapWithKey #-}
403+
404+traverseWithKey :: Applicative t => (k -> a -> t b) -> MonoidalMap k a -> t (MonoidalMap k b)
405+traverseWithKey = itraverse
406+{-# INLINE traverseWithKey #-}
407+
408+mapAccum :: forall k a b c. (a -> b -> (a, c)) -> a -> MonoidalMap k b -> (a, MonoidalMap k c)
409+mapAccum = coerce (M.mapAccum :: (a -> b -> (a, c)) -> a -> M.Map k b -> (a, M.Map k c))
410+{-# INLINE mapAccum #-}
411+
412+mapAccumWithKey :: forall k a b c. (a -> k -> b -> (a, c)) -> a -> MonoidalMap k b -> (a, MonoidalMap k c)
413+mapAccumWithKey = coerce (M.mapAccumWithKey :: (a -> k -> b -> (a, c)) -> a -> M.Map k b -> (a, M.Map k c))
414+{-# INLINE mapAccumWithKey #-}
415+
416+mapAccumRWithKey :: forall k a b c. (a -> k -> b -> (a, c)) -> a -> MonoidalMap k b -> (a, MonoidalMap k c)
417+mapAccumRWithKey = coerce (M.mapAccumRWithKey :: (a -> k -> b -> (a, c)) -> a -> M.Map k b -> (a, M.Map k c))
418+{-# INLINE mapAccumRWithKey #-}
419+
420+mapKeys :: forall k1 k2 a. Ord k2 => (k1 -> k2) -> MonoidalMap k1 a -> MonoidalMap k2 a
421+mapKeys = coerce (M.mapKeys :: (k1 -> k2) -> M.Map k1 a -> M.Map k2 a)
422+{-# INLINE mapKeys #-}
423+
424+mapKeysWith :: forall k1 k2 a. Ord k2 => (a -> a -> a) -> (k1 -> k2) -> MonoidalMap k1 a -> MonoidalMap k2 a
425+mapKeysWith = coerce (M.mapKeysWith :: (a -> a -> a) -> (k1 -> k2) -> M.Map k1 a -> M.Map k2 a)
426+{-# INLINE mapKeysWith #-}
427+
428+mapKeysMonotonic :: forall k1 k2 a. (k1 -> k2) -> MonoidalMap k1 a -> MonoidalMap k2 a
429+mapKeysMonotonic = coerce (M.mapKeysMonotonic :: (k1 -> k2) -> M.Map k1 a -> M.Map k2 a)
430+{-# INLINE mapKeysMonotonic #-}
431+
432+foldr :: forall k a b. (a -> b -> b) -> b -> MonoidalMap k a -> b
433+foldr = coerce (M.foldr :: (a -> b -> b) -> b -> M.Map k a -> b)
434+{-# INLINE foldr #-}
435+
436+foldl :: forall k a b. (a -> b -> a) -> a -> MonoidalMap k b -> a
437+foldl = coerce (M.foldl :: (a -> b -> a) -> a -> M.Map k b -> a)
438+{-# INLINE foldl #-}
439+
440+foldrWithKey :: forall k a b. (k -> a -> b -> b) -> b -> MonoidalMap k a -> b
441+foldrWithKey = coerce (M.foldrWithKey :: (k -> a -> b -> b) -> b -> M.Map k a -> b)
442+{-# INLINE foldrWithKey #-}
443+
444+foldlWithKey :: forall k a b. (a -> k -> b -> a) -> a -> MonoidalMap k b -> a
445+foldlWithKey = coerce (M.foldlWithKey :: (a -> k -> b -> a) -> a -> M.Map k b -> a)
446+{-# INLINE foldlWithKey #-}
447+
448+foldMapWithKey :: forall k a m. Monoid m => (k -> a -> m) -> MonoidalMap k a -> m
449+foldMapWithKey = coerce (M.foldMapWithKey :: Monoid m => (k -> a -> m) -> M.Map k a -> m)
450+{-# INLINE foldMapWithKey #-}
451+
452+foldr' :: forall k a b. (a -> b -> b) -> b -> MonoidalMap k a -> b
453+foldr' = coerce (M.foldr' :: (a -> b -> b) -> b -> M.Map k a -> b)
454+{-# INLINE foldr' #-}
455+
456+foldl' :: forall k a b. (a -> b -> a) -> a -> MonoidalMap k b -> a
457+foldl' = coerce (M.foldl' :: (a -> b -> a) -> a -> M.Map k b -> a)
458+{-# INLINE foldl' #-}
459+
460+foldrWithKey' :: forall k a b. (k -> a -> b -> b) -> b -> MonoidalMap k a -> b
461+foldrWithKey' = coerce (M.foldrWithKey' :: (k -> a -> b -> b) -> b -> M.Map k a -> b)
462+{-# INLINE foldrWithKey' #-}
463+
464+foldlWithKey' :: forall k a b. (a -> k -> b -> a) -> a -> MonoidalMap k b -> a
465+foldlWithKey' = coerce (M.foldlWithKey' :: (a -> k -> b -> a) -> a -> M.Map k b -> a)
466+{-# INLINE foldlWithKey' #-}
467+
468+keysSet :: forall k a. MonoidalMap k a -> Set k
469+keysSet = coerce (M.keysSet :: M.Map k a -> Set k)
470+{-# INLINE keysSet #-}
471+
472+fromSet :: forall k a. (k -> a) -> Set k -> MonoidalMap k a
473+fromSet = coerce (M.fromSet :: (k -> a) -> Set k -> M.Map k a)
474+{-# INLINE fromSet #-}
475+
476+toList :: forall k a. MonoidalMap k a -> [(k, a)]
477+toList = coerce (M.toList :: M.Map k a -> [(k, a)])
478+{-# INLINE toList #-}
479+
480+fromList :: forall k a. Ord k => [(k, a)] -> MonoidalMap k a
481+fromList = coerce (M.fromList :: [(k, a)] -> M.Map k a)
482+{-# INLINE fromList #-}
483+
484+fromListWith :: forall k a. Ord k => (a -> a -> a) -> [(k, a)] -> MonoidalMap k a
485+fromListWith = coerce (M.fromListWith :: (a -> a -> a) -> [(k, a)] -> M.Map k a)
486+{-# INLINE fromListWith #-}
487+
488+fromListWithKey :: forall k a. Ord k => (k -> a -> a -> a) -> [(k, a)] -> MonoidalMap k a
489+fromListWithKey = coerce (M.fromListWithKey :: (k -> a -> a -> a) -> [(k, a)] -> M.Map k a)
490+{-# INLINE fromListWithKey #-}
491+
492+toAscList :: forall k a. MonoidalMap k a -> [(k, a)]
493+toAscList = coerce (M.toAscList :: M.Map k a -> [(k, a)])
494+{-# INLINE toAscList #-}
495+
496+toDescList :: forall k a. MonoidalMap k a -> [(k, a)]
497+toDescList = coerce (M.toDescList :: M.Map k a -> [(k, a)])
498+{-# INLINE toDescList #-}
499+
500+fromAscList :: forall k a. Eq k => [(k, a)] -> MonoidalMap k a
501+fromAscList = coerce (M.fromAscList :: [(k, a)] -> M.Map k a)
502+{-# INLINE fromAscList #-}
503+
504+fromAscListWith :: forall k a. Eq k => (a -> a -> a) -> [(k, a)] -> MonoidalMap k a
505+fromAscListWith = coerce (M.fromAscListWith :: (a -> a -> a) -> [(k, a)] -> M.Map k a)
506+{-# INLINE fromAscListWith #-}
507+
508+fromAscListWithKey :: forall k a. Eq k => (k -> a -> a -> a) -> [(k, a)] -> MonoidalMap k a
509+fromAscListWithKey = coerce (M.fromAscListWithKey :: (k -> a -> a -> a) -> [(k, a)] -> M.Map k a)
510+{-# INLINE fromAscListWithKey #-}
511+
512+fromDistinctAscList :: forall k a. [(k, a)] -> MonoidalMap k a
513+fromDistinctAscList = coerce (M.fromDistinctAscList :: [(k, a)] -> M.Map k a)
514+{-# INLINE fromDistinctAscList #-}
515+
516+filter :: forall k a. (a -> Bool) -> MonoidalMap k a -> MonoidalMap k a
517+filter = coerce (M.filter :: (a -> Bool) -> M.Map k a -> M.Map k a)
518+{-# INLINE filter #-}
519+
520+filterWithKey :: forall k a. (k -> a -> Bool) -> MonoidalMap k a -> MonoidalMap k a
521+filterWithKey = coerce (M.filterWithKey :: (k -> a -> Bool) -> M.Map k a -> M.Map k a)
522+{-# INLINE filterWithKey #-}
523+
524+partition :: forall k a. (a -> Bool) -> MonoidalMap k a -> (MonoidalMap k a, MonoidalMap k a)
525+partition = coerce (M.partition :: (a -> Bool) -> M.Map k a -> (M.Map k a, M.Map k a))
526+{-# INLINE partition #-}
527+
528+partitionWithKey :: forall k a. (k -> a -> Bool) -> MonoidalMap k a -> (MonoidalMap k a, MonoidalMap k a)
529+partitionWithKey = coerce (M.partitionWithKey :: (k -> a -> Bool) -> M.Map k a -> (M.Map k a, M.Map k a))
530+{-# INLINE partitionWithKey #-}
531+
532+mapMaybe :: forall k a b. (a -> Maybe b) -> MonoidalMap k a -> MonoidalMap k b
533+mapMaybe = coerce (M.mapMaybe :: (a -> Maybe b) -> M.Map k a -> M.Map k b)
534+{-# INLINE mapMaybe #-}
535+
536+mapMaybeWithKey :: forall k a b. (k -> a -> Maybe b) -> MonoidalMap k a -> MonoidalMap k b
537+mapMaybeWithKey = coerce (M.mapMaybeWithKey :: (k -> a -> Maybe b) -> M.Map k a -> M.Map k b)
538+{-# INLINE mapMaybeWithKey #-}
539+
540+mapEither :: forall k a b c. (a -> Either b c) -> MonoidalMap k a -> (MonoidalMap k b, MonoidalMap k c)
541+mapEither = coerce (M.mapEither :: (a -> Either b c) -> M.Map k a -> (M.Map k b, M.Map k c))
542+{-# INLINE mapEither #-}
543+
544+mapEitherWithKey :: forall k a b c. (k -> a -> Either b c) -> MonoidalMap k a -> (MonoidalMap k b, MonoidalMap k c)
545+mapEitherWithKey = coerce (M.mapEitherWithKey :: (k -> a -> Either b c) -> M.Map k a -> (M.Map k b, M.Map k c))
546+{-# INLINE mapEitherWithKey #-}
547+
548+split :: forall k a. Ord k => k -> MonoidalMap k a -> (MonoidalMap k a, MonoidalMap k a)
549+split = coerce (M.split :: k -> M.Map k a -> (M.Map k a, M.Map k a))
550+{-# INLINE split #-}
551+
552+splitLookup :: forall k a. Ord k => k -> MonoidalMap k a -> (MonoidalMap k a, Maybe a, MonoidalMap k a)
553+splitLookup = coerce (M.splitLookup :: k -> M.Map k a -> (M.Map k a, Maybe a, M.Map k a))
554+{-# INLINE splitLookup #-}
555+
556+splitRoot :: forall k a. MonoidalMap k a -> [MonoidalMap k a]
557+splitRoot = coerce (M.splitRoot :: M.Map k a -> [M.Map k a])
558+{-# INLINE splitRoot #-}
559+
560+isSubmapOf :: forall k a. (Ord k, Eq a) => MonoidalMap k a -> MonoidalMap k a -> Bool
561+isSubmapOf = coerce (M.isSubmapOf :: M.Map k a -> M.Map k a -> Bool)
562+{-# INLINE isSubmapOf #-}
563+
564+isSubmapOfBy :: forall k a b. Ord k => (a -> b -> Bool) -> MonoidalMap k a -> MonoidalMap k b -> Bool
565+isSubmapOfBy = coerce (M.isSubmapOfBy :: (a -> b -> Bool) -> M.Map k a -> M.Map k b -> Bool)
566+{-# INLINE isSubmapOfBy #-}
567+
568+isProperSubmapOf :: forall k a. (Ord k, Eq a) => MonoidalMap k a -> MonoidalMap k a -> Bool
569+isProperSubmapOf = coerce (M.isProperSubmapOf :: M.Map k a -> M.Map k a -> Bool)
570+{-# INLINE isProperSubmapOf #-}
571+
572+isProperSubmapOfBy :: forall k a b. Ord k => (a -> b -> Bool) -> MonoidalMap k a -> MonoidalMap k b -> Bool
573+isProperSubmapOfBy = coerce (M.isProperSubmapOfBy :: (a -> b -> Bool) -> M.Map k a -> M.Map k b -> Bool)
574+{-# INLINE isProperSubmapOfBy #-}
575+
576+lookupIndex :: forall k a. Ord k => k -> MonoidalMap k a -> Maybe Int
577+lookupIndex = coerce (M.lookupIndex :: k -> M.Map k a -> Maybe Int)
578+{-# INLINE lookupIndex #-}
579+
580+findIndex :: forall k a. Ord k => k -> MonoidalMap k a -> Int
581+findIndex = coerce (M.findIndex :: k -> M.Map k a -> Int)
582+{-# INLINE findIndex #-}
583+
584+elemAt :: forall k a. Int -> MonoidalMap k a -> (k, a)
585+elemAt = coerce (M.elemAt :: Int -> M.Map k a -> (k, a))
586+{-# INLINE elemAt #-}
587+
588+updateAt :: forall k a. (k -> a -> Maybe a) -> Int -> MonoidalMap k a -> MonoidalMap k a
589+updateAt = coerce (M.updateAt :: (k -> a -> Maybe a) -> Int -> M.Map k a -> M.Map k a)
590+{-# INLINE updateAt #-}
591+
592+deleteAt :: forall k a. Int -> MonoidalMap k a -> MonoidalMap k a
593+deleteAt = coerce (M.deleteAt :: Int -> M.Map k a -> M.Map k a)
594+{-# INLINE deleteAt #-}
595+
596+findMin :: forall k a. MonoidalMap k a -> (k, a)
597+findMin = coerce (M.findMin :: M.Map k a -> (k, a))
598+{-# INLINE findMin #-}
599+
600+findMax :: forall k a. MonoidalMap k a -> (k, a)
601+findMax = coerce (M.findMax :: M.Map k a -> (k, a))
602+{-# INLINE findMax #-}
603+
604+deleteMin :: forall k a. MonoidalMap k a -> MonoidalMap k a
605+deleteMin = coerce (M.deleteMin :: M.Map k a -> M.Map k a)
606+{-# INLINE deleteMin #-}
607+
608+deleteMax :: forall k a. MonoidalMap k a -> MonoidalMap k a
609+deleteMax = coerce (M.deleteMax :: M.Map k a -> M.Map k a)
610+{-# INLINE deleteMax #-}
611+
612+deleteFindMin :: forall k a. MonoidalMap k a -> ((k, a), MonoidalMap k a)
613+deleteFindMin = coerce (M.deleteFindMin :: M.Map k a -> ((k, a), M.Map k a))
614+{-# INLINE deleteFindMin #-}
615+
616+deleteFindMax :: forall k a. MonoidalMap k a -> ((k, a), MonoidalMap k a)
617+deleteFindMax = coerce (M.deleteFindMax :: M.Map k a -> ((k, a), M.Map k a))
618+{-# INLINE deleteFindMax #-}
619+
620+updateMin :: forall k a. (a -> Maybe a) -> MonoidalMap k a -> MonoidalMap k a
621+updateMin = coerce (M.updateMin :: (a -> Maybe a) -> M.Map k a -> M.Map k a)
622+{-# INLINE updateMin #-}
623+
624+updateMax :: forall k a. (a -> Maybe a) -> MonoidalMap k a -> MonoidalMap k a
625+updateMax = coerce (M.updateMax :: (a -> Maybe a) -> M.Map k a -> M.Map k a)
626+{-# INLINE updateMax #-}
627+
628+updateMinWithKey :: forall k a. (k -> a -> Maybe a) -> MonoidalMap k a -> MonoidalMap k a
629+updateMinWithKey = coerce (M.updateMinWithKey :: (k -> a -> Maybe a) -> M.Map k a -> M.Map k a)
630+{-# INLINE updateMinWithKey #-}
631+
632+updateMaxWithKey :: forall k a. (k -> a -> Maybe a) -> MonoidalMap k a -> MonoidalMap k a
633+updateMaxWithKey = coerce (M.updateMaxWithKey :: (k -> a -> Maybe a) -> M.Map k a -> M.Map k a)
634+{-# INLINE updateMaxWithKey #-}
635+
636+minView :: forall k a. MonoidalMap k a -> Maybe (a, MonoidalMap k a)
637+minView = coerce (M.minView :: M.Map k a -> Maybe (a, M.Map k a))
638+{-# INLINE minView #-}
639+
640+maxView :: forall k a. MonoidalMap k a -> Maybe (a, MonoidalMap k a)
641+maxView = coerce (M.maxView :: M.Map k a -> Maybe (a, M.Map k a))
642+{-# INLINE maxView #-}
643+
644+minViewWithKey :: forall k a. MonoidalMap k a -> Maybe ((k, a), MonoidalMap k a)
645+minViewWithKey = coerce (M.minViewWithKey :: M.Map k a -> Maybe ((k, a), M.Map k a))
646+{-# INLINE minViewWithKey #-}
647+
648+maxViewWithKey :: forall k a. MonoidalMap k a -> Maybe ((k, a), MonoidalMap k a)
649+maxViewWithKey = coerce (M.maxViewWithKey :: M.Map k a -> Maybe ((k, a), M.Map k a))
650+{-# INLINE maxViewWithKey #-}
651+
652+-- showTree :: forall k a. (Show k, Show a) => MonoidalMap k a -> String
653+-- showTree = coerce (M.showTree :: (Show k, Show a) => M.Map k a -> String)
654+-- {-# INLINE showTree #-}
655+
656+-- showTreeWith :: forall k a. (k -> a -> String) -> Bool -> Bool -> MonoidalMap k a -> String
657+-- showTreeWith = coerce (M.showTreeWith :: (k -> a -> String) -> Bool -> Bool -> M.Map k a -> String)
658+-- {-# INLINE showTreeWith #-}
659+
660+valid :: forall k a. Ord k => MonoidalMap k a -> Bool
661+valid = coerce (M.valid :: Ord k => M.Map k a -> Bool)
662+{-# INLINE valid #-}
663+
664+
src/Data/Map/Monoidal/Strict.hs+502−6
@@ -5,6 +5,8 @@
55{-# LANGUAGE GeneralizedNewtypeDeriving #-}
66{-# LANGUAGE DeriveTraversable #-}
77{-# LANGUAGE DeriveDataTypeable #-}
8+{-# LANGUAGE ScopedTypeVariables #-}
9+{-# LANGUAGE StandaloneDeriving #-}
810
911-- | This module provides a 'Data.Map' variant which uses the value's
1012-- 'Monoid' instance to accumulate conflicting entries when merging
@@ -26,30 +28,141 @@ module Data.Map.Monoidal.Strict
2628 , assocs
2729 , elems
2830 , 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+ , fromList
66+ , fromListWith
67+ , fromListWithKey
68+ , fromSet
69+ , insert
70+ , insertLookupWithKey
71+ , insertWith
72+ , insertWithKey
73+ , intersectionWith
74+ , intersectionWithKey
75+ , isProperSubmapOf
76+ , isProperSubmapOfBy
77+ , isSubmapOf
78+ , isSubmapOfBy
79+ , keysSet
80+ , lookup
81+ , lookupGE
82+ , lookupGT
83+ , lookupIndex
84+ , lookupLE
85+ , lookupLT
86+ , map
87+ , mapAccum
88+ , mapAccumRWithKey
89+ , mapAccumWithKey
90+ , mapEither
91+ , mapEitherWithKey
92+ , mapKeys
93+ , mapKeysMonotonic
94+ , mapKeysWith
95+ , mapMaybe
96+ , mapMaybeWithKey
97+ , mapWithKey
98+ , maxView
99+ , maxViewWithKey
100+ , mergeWithKey
101+ , minView
102+ , minViewWithKey
103+ , null
104+ , partition
105+ , partitionWithKey
106+ , split
107+ , splitLookup
108+ , splitRoot
109+ , toAscList
110+ , toDescList
111+ , toList
112+ , traverseWithKey
113+ , unionWith
114+ , unionWithKey
115+ , unionsWith
116+ , update
117+ , updateAt
118+ , updateLookupWithKey
119+ , updateMax
120+ , updateMaxWithKey
121+ , updateMin
122+ , updateMinWithKey
123+ , updateWithKey
124+ , valid
125+ -- , showTree
126+ -- , showTreeWith
29127 ) where
30128
129+import Prelude hiding (null, lookup, map, foldl, foldr, filter)
130+
131+import Data.Coerce (coerce)
31132import Data.Semigroup
32133import Data.Foldable (Foldable)
33134import Data.Traversable (Traversable)
34135import Control.Applicative (Applicative, pure)
35136import Data.Data (Data)
36137import Data.Typeable (Typeable)
138+import Data.Set (Set)
37139
38140#if MIN_VERSION_base(4,7,0)
39−import GHC.Exts (IsList(..))
141+import qualified GHC.Exts as IsList
40142#endif
41143
42144import Control.DeepSeq
43145import qualified Data.Map.Strict as M
44146import Control.Lens
45147import Control.Newtype
148+import Data.Aeson(FromJSON, ToJSON, FromJSON1, ToJSON1)
149+#if MIN_VERSION_containers(0,5,9)
150+import Data.Functor.Classes
151+#endif
46152
47153-- | A 'Map' with monoidal accumulation
48154newtype MonoidalMap k a = MonoidalMap { getMonoidalMap :: M.Map k a }
49155 deriving (Show, Read, Functor, Eq, Ord, NFData,
50156 Foldable, Traversable,
157+ FromJSON, ToJSON, FromJSON1, ToJSON1,
51158 Data, Typeable)
52159
160+#if MIN_VERSION_containers(0,5,9)
161+deriving instance (Ord k) => Eq1 (MonoidalMap k)
162+deriving instance (Ord k) => Ord1 (MonoidalMap k)
163+deriving instance (Show k) => Show1 (MonoidalMap k)
164+#endif
165+
53166type instance Index (MonoidalMap k a) = k
54167type instance IxValue (MonoidalMap k a) = a
55168instance Ord k => Ixed (MonoidalMap k a) where
@@ -67,9 +180,9 @@ instance Ord k => At (MonoidalMap k a) where
67180
68181instance Each (MonoidalMap k a) (MonoidalMap k b) a b
69182
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
183+instance FunctorWithIndex k (MonoidalMap k)
184+instance FoldableWithIndex k (MonoidalMap k)
185+instance TraversableWithIndex k (MonoidalMap k) where
73186 itraverse f (MonoidalMap m) = fmap MonoidalMap $ itraverse f m
74187 {-# INLINE itraverse #-}
75188
@@ -108,7 +221,7 @@ instance Newtype (MonoidalMap k a) (M.Map k a) where
108221 {-# INLINE unpack #-}
109222
110223#if MIN_VERSION_base(4,7,0)
111−instance (Ord k, Semigroup a) => IsList (MonoidalMap k a) where
224+instance (Ord k, Semigroup a) => IsList.IsList (MonoidalMap k a) where
112225 type Item (MonoidalMap k a) = (k, a)
113226 fromList = MonoidalMap . M.fromListWith (<>)
114227 {-# INLINE fromList #-}
@@ -117,7 +230,7 @@ instance (Ord k, Semigroup a) => IsList (MonoidalMap k a) where
117230#endif
118231
119232-- | /O(1)/. A map with a single element.
120−singleton :: Ord k => k -> a -> MonoidalMap k a
233+singleton :: k -> a -> MonoidalMap k a
121234singleton k a = MonoidalMap $ M.singleton k a
122235{-# INLINE singleton #-}
123236
@@ -165,3 +278,386 @@ elems = M.elems . unpack
165278keys :: MonoidalMap k a -> [k]
166279keys = M.keys . unpack
167280{-# INLINE keys #-}
281+
282+
283+(!) :: forall k a. Ord k => MonoidalMap k a -> k -> a
284+(!) = coerce ((M.!) :: M.Map k a -> k -> a)
285+infixl 9 !
286+
287+(\\) :: forall k a b. Ord k => MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k a
288+(\\) = coerce ((M.\\) :: M.Map k a -> M.Map k b -> M.Map k a)
289+infixl 9 \\ --
290+
291+null :: forall k a. MonoidalMap k a -> Bool
292+null = coerce (M.null :: M.Map k a -> Bool)
293+{-# INLINE null #-}
294+
295+lookup :: forall k a. Ord k => k -> MonoidalMap k a -> Maybe a
296+lookup = coerce (M.lookup :: k -> M.Map k a -> Maybe a)
297+{-# INLINE lookup #-}
298+
299+lookupLT :: forall k a. Ord k => k -> MonoidalMap k a -> Maybe (k, a)
300+lookupLT = coerce (M.lookupLT :: k -> M.Map k a -> Maybe (k,a))
301+{-# INLINE lookupLT #-}
302+
303+lookupGT :: forall k a. Ord k => k -> MonoidalMap k a -> Maybe (k, a)
304+lookupGT = coerce (M.lookupGT :: k -> M.Map k a -> Maybe (k,a))
305+{-# INLINE lookupGT #-}
306+
307+lookupLE :: forall k a. Ord k => k -> MonoidalMap k a -> Maybe (k, a)
308+lookupLE = coerce (M.lookupLE :: k -> M.Map k a -> Maybe (k,a))
309+{-# INLINE lookupLE #-}
310+
311+lookupGE :: forall k a. Ord k => k -> MonoidalMap k a -> Maybe (k, a)
312+lookupGE = coerce (M.lookupGE :: k -> M.Map k a -> Maybe (k,a))
313+{-# INLINE lookupGE #-}
314+
315+empty :: forall k a. MonoidalMap k a
316+empty = coerce (M.empty :: M.Map k a)
317+{-# INLINE empty #-}
318+
319+insert :: forall k a. Ord k => k -> a -> MonoidalMap k a -> MonoidalMap k a
320+insert = coerce (M.insert :: k -> a -> M.Map k a -> M.Map k a)
321+{-# INLINE insert #-}
322+
323+insertWith :: forall k a. Ord k => (a -> a -> a) -> k -> a -> MonoidalMap k a -> MonoidalMap k a
324+insertWith = coerce (M.insertWith :: (a -> a -> a) -> k -> a -> M.Map k a -> M.Map k a)
325+{-# INLINE insertWith #-}
326+
327+insertWithKey :: forall k a. Ord k => (k -> a -> a -> a) -> k -> a -> MonoidalMap k a -> MonoidalMap k a
328+insertWithKey = coerce (M.insertWithKey :: (k -> a -> a -> a) -> k -> a -> M.Map k a -> M.Map k a)
329+{-# INLINE insertWithKey #-}
330+
331+insertLookupWithKey :: forall k a. Ord k => (k -> a -> a -> a) -> k -> a -> MonoidalMap k a -> (Maybe a, MonoidalMap k a)
332+insertLookupWithKey = coerce (M.insertLookupWithKey :: (k -> a -> a -> a) -> k -> a -> M.Map k a -> (Maybe a, M.Map k a))
333+{-# INLINE insertLookupWithKey #-}
334+
335+adjust :: forall k a. Ord k => (a -> a) -> k -> MonoidalMap k a -> MonoidalMap k a
336+adjust = coerce (M.adjust :: (a -> a) -> k -> M.Map k a -> M.Map k a)
337+{-# INLINE adjust #-}
338+
339+adjustWithKey :: forall k a. Ord k => (k -> a -> a) -> k -> MonoidalMap k a -> MonoidalMap k a
340+adjustWithKey = coerce (M.adjustWithKey :: (k -> a -> a) -> k -> M.Map k a -> M.Map k a)
341+{-# INLINE adjustWithKey #-}
342+
343+update :: forall k a. Ord k => (a -> Maybe a) -> k -> MonoidalMap k a -> MonoidalMap k a
344+update = coerce (M.update :: (a -> Maybe a) -> k -> M.Map k a -> M.Map k a)
345+{-# INLINE update #-}
346+
347+updateWithKey :: forall k a. Ord k => (k -> a -> Maybe a) -> k -> MonoidalMap k a -> MonoidalMap k a
348+updateWithKey = coerce (M.updateWithKey :: (k -> a -> Maybe a) -> k -> M.Map k a -> M.Map k a)
349+{-# INLINE updateWithKey #-}
350+
351+updateLookupWithKey :: forall k a. Ord k => (k -> a -> Maybe a) -> k -> MonoidalMap k a -> (Maybe a, MonoidalMap k a)
352+updateLookupWithKey = coerce (M.updateLookupWithKey :: (k -> a -> Maybe a) -> k -> M.Map k a -> (Maybe a, M.Map k a))
353+{-# INLINE updateLookupWithKey #-}
354+
355+alter :: forall k a. Ord k => (Maybe a -> Maybe a) -> k -> MonoidalMap k a -> MonoidalMap k a
356+alter = coerce (M.alter :: (Maybe a -> Maybe a) -> k -> M.Map k a -> M.Map k a)
357+{-# INLINE alter #-}
358+
359+unionWith :: forall k a. Ord k => (a -> a -> a) -> MonoidalMap k a -> MonoidalMap k a -> MonoidalMap k a
360+unionWith = coerce (M.unionWith :: (a -> a -> a) -> M.Map k a -> M.Map k a -> M.Map k a)
361+{-# INLINE unionWith #-}
362+
363+unionWithKey :: forall k a. Ord k => (k -> a -> a -> a) -> MonoidalMap k a -> MonoidalMap k a -> MonoidalMap k a
364+unionWithKey = coerce (M.unionWithKey :: (k -> a -> a -> a) -> M.Map k a -> M.Map k a -> M.Map k a)
365+{-# INLINE unionWithKey #-}
366+
367+unionsWith :: forall k a. Ord k => (a -> a -> a) -> [MonoidalMap k a] -> MonoidalMap k a
368+unionsWith = coerce (M.unionsWith :: (a -> a -> a) -> [M.Map k a] -> M.Map k a)
369+{-# INLINE unionsWith #-}
370+
371+difference :: forall k a b. Ord k => MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k a
372+difference = (\\)
373+{-# INLINE difference #-}
374+
375+differenceWith :: forall k a b. Ord k => (a -> b -> Maybe a) -> MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k a
376+differenceWith = coerce (M.differenceWith :: (a -> b -> Maybe a) -> M.Map k a -> M.Map k b -> M.Map k a)
377+{-# INLINE differenceWith #-}
378+
379+differenceWithKey :: forall k a b. Ord k => (k -> a -> b -> Maybe a) -> MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k a
380+differenceWithKey = coerce (M.differenceWithKey :: (k -> a -> b -> Maybe a) -> M.Map k a -> M.Map k b -> M.Map k a)
381+{-# INLINE differenceWithKey #-}
382+
383+intersectionWith :: forall k a b c. Ord k => (a -> b -> c) -> MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k c
384+intersectionWith = coerce (M.intersectionWith :: (a -> b -> c) -> M.Map k a -> M.Map k b -> M.Map k c)
385+{-# INLINE intersectionWith #-}
386+
387+intersectionWithKey :: forall k a b c. Ord k => (k -> a -> b -> c) -> MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k c
388+intersectionWithKey = coerce (M.intersectionWithKey :: (k -> a -> b -> c) -> M.Map k a -> M.Map k b -> M.Map k c)
389+{-# INLINE intersectionWithKey #-}
390+
391+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
392+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)
393+{-# INLINE mergeWithKey #-}
394+
395+map :: (a -> b) -> MonoidalMap k a -> MonoidalMap k b
396+map = fmap
397+{-# INLINE map #-}
398+
399+mapWithKey :: forall k a b. (k -> a -> b) -> MonoidalMap k a -> MonoidalMap k b
400+mapWithKey = coerce (M.mapWithKey :: (k -> a -> b) -> M.Map k a -> M.Map k b)
401+{-# INLINE mapWithKey #-}
402+
403+traverseWithKey :: Applicative t => (k -> a -> t b) -> MonoidalMap k a -> t (MonoidalMap k b)
404+traverseWithKey = itraverse
405+{-# INLINE traverseWithKey #-}
406+
407+mapAccum :: forall k a b c. (a -> b -> (a, c)) -> a -> MonoidalMap k b -> (a, MonoidalMap k c)
408+mapAccum = coerce (M.mapAccum :: (a -> b -> (a, c)) -> a -> M.Map k b -> (a, M.Map k c))
409+{-# INLINE mapAccum #-}
410+
411+mapAccumWithKey :: forall k a b c. (a -> k -> b -> (a, c)) -> a -> MonoidalMap k b -> (a, MonoidalMap k c)
412+mapAccumWithKey = coerce (M.mapAccumWithKey :: (a -> k -> b -> (a, c)) -> a -> M.Map k b -> (a, M.Map k c))
413+{-# INLINE mapAccumWithKey #-}
414+
415+mapAccumRWithKey :: forall k a b c. (a -> k -> b -> (a, c)) -> a -> MonoidalMap k b -> (a, MonoidalMap k c)
416+mapAccumRWithKey = coerce (M.mapAccumRWithKey :: (a -> k -> b -> (a, c)) -> a -> M.Map k b -> (a, M.Map k c))
417+{-# INLINE mapAccumRWithKey #-}
418+
419+mapKeys :: forall k1 k2 a. Ord k2 => (k1 -> k2) -> MonoidalMap k1 a -> MonoidalMap k2 a
420+mapKeys = coerce (M.mapKeys :: (k1 -> k2) -> M.Map k1 a -> M.Map k2 a)
421+{-# INLINE mapKeys #-}
422+
423+mapKeysWith :: forall k1 k2 a. Ord k2 => (a -> a -> a) -> (k1 -> k2) -> MonoidalMap k1 a -> MonoidalMap k2 a
424+mapKeysWith = coerce (M.mapKeysWith :: (a -> a -> a) -> (k1 -> k2) -> M.Map k1 a -> M.Map k2 a)
425+{-# INLINE mapKeysWith #-}
426+
427+mapKeysMonotonic :: forall k1 k2 a. (k1 -> k2) -> MonoidalMap k1 a -> MonoidalMap k2 a
428+mapKeysMonotonic = coerce (M.mapKeysMonotonic :: (k1 -> k2) -> M.Map k1 a -> M.Map k2 a)
429+{-# INLINE mapKeysMonotonic #-}
430+
431+foldr :: forall k a b. (a -> b -> b) -> b -> MonoidalMap k a -> b
432+foldr = coerce (M.foldr :: (a -> b -> b) -> b -> M.Map k a -> b)
433+{-# INLINE foldr #-}
434+
435+foldl :: forall k a b. (a -> b -> a) -> a -> MonoidalMap k b -> a
436+foldl = coerce (M.foldl :: (a -> b -> a) -> a -> M.Map k b -> a)
437+{-# INLINE foldl #-}
438+
439+foldrWithKey :: forall k a b. (k -> a -> b -> b) -> b -> MonoidalMap k a -> b
440+foldrWithKey = coerce (M.foldrWithKey :: (k -> a -> b -> b) -> b -> M.Map k a -> b)
441+{-# INLINE foldrWithKey #-}
442+
443+foldlWithKey :: forall k a b. (a -> k -> b -> a) -> a -> MonoidalMap k b -> a
444+foldlWithKey = coerce (M.foldlWithKey :: (a -> k -> b -> a) -> a -> M.Map k b -> a)
445+{-# INLINE foldlWithKey #-}
446+
447+foldMapWithKey :: forall k a m. Monoid m => (k -> a -> m) -> MonoidalMap k a -> m
448+foldMapWithKey = coerce (M.foldMapWithKey :: Monoid m => (k -> a -> m) -> M.Map k a -> m)
449+{-# INLINE foldMapWithKey #-}
450+
451+foldr' :: forall k a b. (a -> b -> b) -> b -> MonoidalMap k a -> b
452+foldr' = coerce (M.foldr' :: (a -> b -> b) -> b -> M.Map k a -> b)
453+{-# INLINE foldr' #-}
454+
455+foldl' :: forall k a b. (a -> b -> a) -> a -> MonoidalMap k b -> a
456+foldl' = coerce (M.foldl' :: (a -> b -> a) -> a -> M.Map k b -> a)
457+{-# INLINE foldl' #-}
458+
459+foldrWithKey' :: forall k a b. (k -> a -> b -> b) -> b -> MonoidalMap k a -> b
460+foldrWithKey' = coerce (M.foldrWithKey' :: (k -> a -> b -> b) -> b -> M.Map k a -> b)
461+{-# INLINE foldrWithKey' #-}
462+
463+foldlWithKey' :: forall k a b. (a -> k -> b -> a) -> a -> MonoidalMap k b -> a
464+foldlWithKey' = coerce (M.foldlWithKey' :: (a -> k -> b -> a) -> a -> M.Map k b -> a)
465+{-# INLINE foldlWithKey' #-}
466+
467+keysSet :: forall k a. MonoidalMap k a -> Set k
468+keysSet = coerce (M.keysSet :: M.Map k a -> Set k)
469+{-# INLINE keysSet #-}
470+
471+fromSet :: forall k a. (k -> a) -> Set k -> MonoidalMap k a
472+fromSet = coerce (M.fromSet :: (k -> a) -> Set k -> M.Map k a)
473+{-# INLINE fromSet #-}
474+
475+toList :: forall k a. MonoidalMap k a -> [(k, a)]
476+toList = coerce (M.toList :: M.Map k a -> [(k, a)])
477+{-# INLINE toList #-}
478+
479+fromList :: forall k a. Ord k => [(k, a)] -> MonoidalMap k a
480+fromList = coerce (M.fromList :: [(k, a)] -> M.Map k a)
481+{-# INLINE fromList #-}
482+
483+fromListWith :: forall k a. Ord k => (a -> a -> a) -> [(k, a)] -> MonoidalMap k a
484+fromListWith = coerce (M.fromListWith :: (a -> a -> a) -> [(k, a)] -> M.Map k a)
485+{-# INLINE fromListWith #-}
486+
487+fromListWithKey :: forall k a. Ord k => (k -> a -> a -> a) -> [(k, a)] -> MonoidalMap k a
488+fromListWithKey = coerce (M.fromListWithKey :: (k -> a -> a -> a) -> [(k, a)] -> M.Map k a)
489+{-# INLINE fromListWithKey #-}
490+
491+toAscList :: forall k a. MonoidalMap k a -> [(k, a)]
492+toAscList = coerce (M.toAscList :: M.Map k a -> [(k, a)])
493+{-# INLINE toAscList #-}
494+
495+toDescList :: forall k a. MonoidalMap k a -> [(k, a)]
496+toDescList = coerce (M.toDescList :: M.Map k a -> [(k, a)])
497+{-# INLINE toDescList #-}
498+
499+fromAscList :: forall k a. Eq k => [(k, a)] -> MonoidalMap k a
500+fromAscList = coerce (M.fromAscList :: [(k, a)] -> M.Map k a)
501+{-# INLINE fromAscList #-}
502+
503+fromAscListWith :: forall k a. Eq k => (a -> a -> a) -> [(k, a)] -> MonoidalMap k a
504+fromAscListWith = coerce (M.fromAscListWith :: (a -> a -> a) -> [(k, a)] -> M.Map k a)
505+{-# INLINE fromAscListWith #-}
506+
507+fromAscListWithKey :: forall k a. Eq k => (k -> a -> a -> a) -> [(k, a)] -> MonoidalMap k a
508+fromAscListWithKey = coerce (M.fromAscListWithKey :: (k -> a -> a -> a) -> [(k, a)] -> M.Map k a)
509+{-# INLINE fromAscListWithKey #-}
510+
511+fromDistinctAscList :: forall k a. [(k, a)] -> MonoidalMap k a
512+fromDistinctAscList = coerce (M.fromDistinctAscList :: [(k, a)] -> M.Map k a)
513+{-# INLINE fromDistinctAscList #-}
514+
515+filter :: forall k a. (a -> Bool) -> MonoidalMap k a -> MonoidalMap k a
516+filter = coerce (M.filter :: (a -> Bool) -> M.Map k a -> M.Map k a)
517+{-# INLINE filter #-}
518+
519+filterWithKey :: forall k a. (k -> a -> Bool) -> MonoidalMap k a -> MonoidalMap k a
520+filterWithKey = coerce (M.filterWithKey :: (k -> a -> Bool) -> M.Map k a -> M.Map k a)
521+{-# INLINE filterWithKey #-}
522+
523+partition :: forall k a. (a -> Bool) -> MonoidalMap k a -> (MonoidalMap k a, MonoidalMap k a)
524+partition = coerce (M.partition :: (a -> Bool) -> M.Map k a -> (M.Map k a, M.Map k a))
525+{-# INLINE partition #-}
526+
527+partitionWithKey :: forall k a. (k -> a -> Bool) -> MonoidalMap k a -> (MonoidalMap k a, MonoidalMap k a)
528+partitionWithKey = coerce (M.partitionWithKey :: (k -> a -> Bool) -> M.Map k a -> (M.Map k a, M.Map k a))
529+{-# INLINE partitionWithKey #-}
530+
531+mapMaybe :: forall k a b. (a -> Maybe b) -> MonoidalMap k a -> MonoidalMap k b
532+mapMaybe = coerce (M.mapMaybe :: (a -> Maybe b) -> M.Map k a -> M.Map k b)
533+{-# INLINE mapMaybe #-}
534+
535+mapMaybeWithKey :: forall k a b. (k -> a -> Maybe b) -> MonoidalMap k a -> MonoidalMap k b
536+mapMaybeWithKey = coerce (M.mapMaybeWithKey :: (k -> a -> Maybe b) -> M.Map k a -> M.Map k b)
537+{-# INLINE mapMaybeWithKey #-}
538+
539+mapEither :: forall k a b c. (a -> Either b c) -> MonoidalMap k a -> (MonoidalMap k b, MonoidalMap k c)
540+mapEither = coerce (M.mapEither :: (a -> Either b c) -> M.Map k a -> (M.Map k b, M.Map k c))
541+{-# INLINE mapEither #-}
542+
543+mapEitherWithKey :: forall k a b c. (k -> a -> Either b c) -> MonoidalMap k a -> (MonoidalMap k b, MonoidalMap k c)
544+mapEitherWithKey = coerce (M.mapEitherWithKey :: (k -> a -> Either b c) -> M.Map k a -> (M.Map k b, M.Map k c))
545+{-# INLINE mapEitherWithKey #-}
546+
547+split :: forall k a. Ord k => k -> MonoidalMap k a -> (MonoidalMap k a, MonoidalMap k a)
548+split = coerce (M.split :: k -> M.Map k a -> (M.Map k a, M.Map k a))
549+{-# INLINE split #-}
550+
551+splitLookup :: forall k a. Ord k => k -> MonoidalMap k a -> (MonoidalMap k a, Maybe a, MonoidalMap k a)
552+splitLookup = coerce (M.splitLookup :: k -> M.Map k a -> (M.Map k a, Maybe a, M.Map k a))
553+{-# INLINE splitLookup #-}
554+
555+splitRoot :: forall k a. MonoidalMap k a -> [MonoidalMap k a]
556+splitRoot = coerce (M.splitRoot :: M.Map k a -> [M.Map k a])
557+{-# INLINE splitRoot #-}
558+
559+isSubmapOf :: forall k a. (Ord k, Eq a) => MonoidalMap k a -> MonoidalMap k a -> Bool
560+isSubmapOf = coerce (M.isSubmapOf :: M.Map k a -> M.Map k a -> Bool)
561+{-# INLINE isSubmapOf #-}
562+
563+isSubmapOfBy :: forall k a b. Ord k => (a -> b -> Bool) -> MonoidalMap k a -> MonoidalMap k b -> Bool
564+isSubmapOfBy = coerce (M.isSubmapOfBy :: (a -> b -> Bool) -> M.Map k a -> M.Map k b -> Bool)
565+{-# INLINE isSubmapOfBy #-}
566+
567+isProperSubmapOf :: forall k a. (Ord k, Eq a) => MonoidalMap k a -> MonoidalMap k a -> Bool
568+isProperSubmapOf = coerce (M.isProperSubmapOf :: M.Map k a -> M.Map k a -> Bool)
569+{-# INLINE isProperSubmapOf #-}
570+
571+isProperSubmapOfBy :: forall k a b. Ord k => (a -> b -> Bool) -> MonoidalMap k a -> MonoidalMap k b -> Bool
572+isProperSubmapOfBy = coerce (M.isProperSubmapOfBy :: (a -> b -> Bool) -> M.Map k a -> M.Map k b -> Bool)
573+{-# INLINE isProperSubmapOfBy #-}
574+
575+lookupIndex :: forall k a. Ord k => k -> MonoidalMap k a -> Maybe Int
576+lookupIndex = coerce (M.lookupIndex :: k -> M.Map k a -> Maybe Int)
577+{-# INLINE lookupIndex #-}
578+
579+findIndex :: forall k a. Ord k => k -> MonoidalMap k a -> Int
580+findIndex = coerce (M.findIndex :: k -> M.Map k a -> Int)
581+{-# INLINE findIndex #-}
582+
583+elemAt :: forall k a. Int -> MonoidalMap k a -> (k, a)
584+elemAt = coerce (M.elemAt :: Int -> M.Map k a -> (k, a))
585+{-# INLINE elemAt #-}
586+
587+updateAt :: forall k a. (k -> a -> Maybe a) -> Int -> MonoidalMap k a -> MonoidalMap k a
588+updateAt = coerce (M.updateAt :: (k -> a -> Maybe a) -> Int -> M.Map k a -> M.Map k a)
589+{-# INLINE updateAt #-}
590+
591+deleteAt :: forall k a. Int -> MonoidalMap k a -> MonoidalMap k a
592+deleteAt = coerce (M.deleteAt :: Int -> M.Map k a -> M.Map k a)
593+{-# INLINE deleteAt #-}
594+
595+findMin :: forall k a. MonoidalMap k a -> (k, a)
596+findMin = coerce (M.findMin :: M.Map k a -> (k, a))
597+{-# INLINE findMin #-}
598+
599+findMax :: forall k a. MonoidalMap k a -> (k, a)
600+findMax = coerce (M.findMax :: M.Map k a -> (k, a))
601+{-# INLINE findMax #-}
602+
603+deleteMin :: forall k a. MonoidalMap k a -> MonoidalMap k a
604+deleteMin = coerce (M.deleteMin :: M.Map k a -> M.Map k a)
605+{-# INLINE deleteMin #-}
606+
607+deleteMax :: forall k a. MonoidalMap k a -> MonoidalMap k a
608+deleteMax = coerce (M.deleteMax :: M.Map k a -> M.Map k a)
609+{-# INLINE deleteMax #-}
610+
611+deleteFindMin :: forall k a. MonoidalMap k a -> ((k, a), MonoidalMap k a)
612+deleteFindMin = coerce (M.deleteFindMin :: M.Map k a -> ((k, a), M.Map k a))
613+{-# INLINE deleteFindMin #-}
614+
615+deleteFindMax :: forall k a. MonoidalMap k a -> ((k, a), MonoidalMap k a)
616+deleteFindMax = coerce (M.deleteFindMax :: M.Map k a -> ((k, a), M.Map k a))
617+{-# INLINE deleteFindMax #-}
618+
619+updateMin :: forall k a. (a -> Maybe a) -> MonoidalMap k a -> MonoidalMap k a
620+updateMin = coerce (M.updateMin :: (a -> Maybe a) -> M.Map k a -> M.Map k a)
621+{-# INLINE updateMin #-}
622+
623+updateMax :: forall k a. (a -> Maybe a) -> MonoidalMap k a -> MonoidalMap k a
624+updateMax = coerce (M.updateMax :: (a -> Maybe a) -> M.Map k a -> M.Map k a)
625+{-# INLINE updateMax #-}
626+
627+updateMinWithKey :: forall k a. (k -> a -> Maybe a) -> MonoidalMap k a -> MonoidalMap k a
628+updateMinWithKey = coerce (M.updateMinWithKey :: (k -> a -> Maybe a) -> M.Map k a -> M.Map k a)
629+{-# INLINE updateMinWithKey #-}
630+
631+updateMaxWithKey :: forall k a. (k -> a -> Maybe a) -> MonoidalMap k a -> MonoidalMap k a
632+updateMaxWithKey = coerce (M.updateMaxWithKey :: (k -> a -> Maybe a) -> M.Map k a -> M.Map k a)
633+{-# INLINE updateMaxWithKey #-}
634+
635+minView :: forall k a. MonoidalMap k a -> Maybe (a, MonoidalMap k a)
636+minView = coerce (M.minView :: M.Map k a -> Maybe (a, M.Map k a))
637+{-# INLINE minView #-}
638+
639+maxView :: forall k a. MonoidalMap k a -> Maybe (a, MonoidalMap k a)
640+maxView = coerce (M.maxView :: M.Map k a -> Maybe (a, M.Map k a))
641+{-# INLINE maxView #-}
642+
643+minViewWithKey :: forall k a. MonoidalMap k a -> Maybe ((k, a), MonoidalMap k a)
644+minViewWithKey = coerce (M.minViewWithKey :: M.Map k a -> Maybe ((k, a), M.Map k a))
645+{-# INLINE minViewWithKey #-}
646+
647+maxViewWithKey :: forall k a. MonoidalMap k a -> Maybe ((k, a), MonoidalMap k a)
648+maxViewWithKey = coerce (M.maxViewWithKey :: M.Map k a -> Maybe ((k, a), M.Map k a))
649+{-# INLINE maxViewWithKey #-}
650+
651+-- showTree :: forall k a. (Show k, Show a) => MonoidalMap k a -> String
652+-- showTree = coerce (M.showTree :: (Show k, Show a) => M.Map k a -> String)
653+-- {-# INLINE showTree #-}
654+
655+-- showTreeWith :: forall k a. (k -> a -> String) -> Bool -> Bool -> MonoidalMap k a -> String
656+-- showTreeWith = coerce (M.showTreeWith :: (k -> a -> String) -> Bool -> Bool -> M.Map k a -> String)
657+-- {-# INLINE showTreeWith #-}
658+
659+valid :: forall k a. Ord k => MonoidalMap k a -> Bool
660+valid = coerce (M.valid :: Ord k => M.Map k a -> Bool)
661+{-# INLINE valid #-}
662+
663+