Skip to content

Commit eacd675

Browse files
Rename mapAccumWithKey{L,R} to mapAccum{L,R}WithKey. (#221)
2 parents 283ab2f + 460cdcc commit eacd675

File tree

6 files changed

+66
-66
lines changed

6 files changed

+66
-66
lines changed

src/benchmark/Main.hs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,17 @@ main = do
127127
, bench "RecoveredMap" $
128128
nf (mapAccumR (\s v -> (s + v, v)) 0) rm_natural
129129
]
130-
, bgroup "mapAccumWithKeyL"
130+
, bgroup "mapAccumLWithKey"
131131
[ bench "Data.Map.Strict" $
132132
nf (mapAccumL (\s v -> (s + v, v)) 0) om_natural
133133
, bench "RecoveredMap" $
134134
nf (mapAccumL (\s v -> (s + v, v)) 0) rm_natural
135135
]
136-
, bgroup "mapAccumWithKeyR"
136+
, bgroup "mapAccumRWithKey"
137137
[ bench "Data.Map.Strict" $
138-
nf (mapAccumWithKeyR (\s k v -> (s + k + v, v)) 0) om_natural
138+
nf (mapAccumRWithKey (\s k v -> (s + k + v, v)) 0) om_natural
139139
, bench "RecoveredMap" $
140-
nf (mapAccumWithKeyR (\s k v -> (s + k + v, v)) 0) rm_natural
140+
nf (mapAccumRWithKey (\s k v -> (s + k + v, v)) 0) rm_natural
141141
]
142142
]
143143
where
@@ -172,8 +172,8 @@ class Ord k => Map m k v where
172172
lookup :: k -> m k v -> Maybe v
173173
mapAccumL :: (s -> v -> (s, v)) -> s -> m k v -> (s, m k v)
174174
mapAccumR :: (s -> v -> (s, v)) -> s -> m k v -> (s, m k v)
175-
mapAccumWithKeyL :: (s -> k -> v -> (s, v)) -> s -> m k v -> (s, m k v)
176-
mapAccumWithKeyR :: (s -> k -> v -> (s, v)) -> s -> m k v -> (s, m k v)
175+
mapAccumLWithKey :: (s -> k -> v -> (s, v)) -> s -> m k v -> (s, m k v)
176+
mapAccumRWithKey :: (s -> k -> v -> (s, v)) -> s -> m k v -> (s, m k v)
177177

178178
instance Ord k => Map OMap.Map k v where
179179
fromList = OMap.fromList
@@ -182,8 +182,8 @@ instance Ord k => Map OMap.Map k v where
182182
lookup = OMap.lookup
183183
mapAccumL = OMap.mapAccum
184184
mapAccumR f = OMap.mapAccumRWithKey (\s _ v -> f s v)
185-
mapAccumWithKeyL = OMap.mapAccumWithKey
186-
mapAccumWithKeyR = OMap.mapAccumRWithKey
185+
mapAccumLWithKey = OMap.mapAccumWithKey
186+
mapAccumRWithKey = OMap.mapAccumRWithKey
187187

188188
instance (Ord k, Eq v) => Map RMap.Map k v where
189189
fromList = RMap.fromList
@@ -192,8 +192,8 @@ instance (Ord k, Eq v) => Map RMap.Map k v where
192192
lookup = RMap.lookup
193193
mapAccumL = RMap.mapAccumL
194194
mapAccumR = RMap.mapAccumR
195-
mapAccumWithKeyL = RMap.mapAccumWithKeyL
196-
mapAccumWithKeyR = RMap.mapAccumWithKeyR
195+
mapAccumLWithKey = RMap.mapAccumLWithKey
196+
mapAccumRWithKey = RMap.mapAccumRWithKey
197197

198198
deleteMany :: (Map m k v, Num v) => [k] -> m k v -> m k v
199199
deleteMany xs m = foldl' (flip delete) m xs

src/examples/Examples/RecoveredMap.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ module Examples.RecoveredMap
2121
, member
2222
, map
2323
, mapAccumL
24+
, mapAccumLWithKey
2425
, mapAccumR
25-
, mapAccumWithKeyL
26-
, mapAccumWithKeyR
26+
, mapAccumRWithKey
2727
)
2828
where
2929

@@ -98,13 +98,13 @@ mapAccumL f s m = Map <$> MonoidMap.mapAccumL (accum f) s (unMap m)
9898
mapAccumR :: (s -> v1 -> (s, v2)) -> s -> Map k v1 -> (s, Map k v2)
9999
mapAccumR f s m = Map <$> MonoidMap.mapAccumR (accum f) s (unMap m)
100100

101-
mapAccumWithKeyL :: (s -> k -> v1 -> (s, v2)) -> s -> Map k v1 -> (s, Map k v2)
102-
mapAccumWithKeyL f s m =
103-
Map <$> MonoidMap.mapAccumWithKeyL (accumWithKey f) s (unMap m)
101+
mapAccumLWithKey :: (s -> k -> v1 -> (s, v2)) -> s -> Map k v1 -> (s, Map k v2)
102+
mapAccumLWithKey f s m =
103+
Map <$> MonoidMap.mapAccumLWithKey (accumWithKey f) s (unMap m)
104104

105-
mapAccumWithKeyR :: (s -> k -> v1 -> (s, v2)) -> s -> Map k v1 -> (s, Map k v2)
106-
mapAccumWithKeyR f s m =
107-
Map <$> MonoidMap.mapAccumWithKeyR (accumWithKey f) s (unMap m)
105+
mapAccumRWithKey :: (s -> k -> v1 -> (s, v2)) -> s -> Map k v1 -> (s, Map k v2)
106+
mapAccumRWithKey f s m =
107+
Map <$> MonoidMap.mapAccumRWithKey (accumWithKey f) s (unMap m)
108108

109109
--------------------------------------------------------------------------------
110110
-- Utilities

src/internal/Data/MonoidMap/Internal.hs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ module Data.MonoidMap.Internal
8181
, traverse
8282
, traverseWithKey
8383
, mapAccumL
84+
, mapAccumLWithKey
8485
, mapAccumR
85-
, mapAccumWithKeyL
86-
, mapAccumWithKeyR
86+
, mapAccumRWithKey
8787

8888
-- * Monoidal operations
8989

@@ -1273,51 +1273,51 @@ mapAccumR f s m =
12731273
-- Satisfies the following property:
12741274
--
12751275
-- @
1276-
-- 'mapAccumWithKeyL' f s m '=='
1276+
-- 'mapAccumLWithKey' f s m '=='
12771277
-- 'fmap' 'fromMap' ('Map'.'Map.mapAccumWithKey' f s ('toMap' m))
12781278
-- @
12791279
--
12801280
-- @since 0.0.1.9
12811281
--
1282-
mapAccumWithKeyL
1282+
mapAccumLWithKey
12831283
:: MonoidNull v2
12841284
=> (s -> k -> v1 -> (s, v2))
12851285
-> s
12861286
-> MonoidMap k v1
12871287
-> (s, MonoidMap k v2)
1288-
mapAccumWithKeyL f s0 m =
1288+
mapAccumLWithKey f s0 m =
12891289
(coerce
12901290
:: ((k -> v1 -> StateL s v2 ) -> MM k v1 -> StateL s (MM k v2))
12911291
-> ((k -> v1 -> s -> (s, v2)) -> MM k v1 -> s -> (s, MM k v2))
12921292
)
12931293
traverseWithKey (\k v1 s -> f s k v1) m s0
1294-
{-# INLINE mapAccumWithKeyL #-}
1294+
{-# INLINE mapAccumLWithKey #-}
12951295

12961296
-- | \(O(n)\). Threads an accumulating argument through the map in descending
12971297
-- order of keys.
12981298
--
12991299
-- Satisfies the following property:
13001300
--
13011301
-- @
1302-
-- 'mapAccumWithKeyR' f s m '=='
1302+
-- 'mapAccumRWithKey' f s m '=='
13031303
-- 'fmap' 'fromMap' ('Map'.'Map.mapAccumRWithKey' f s ('toMap' m))
13041304
-- @
13051305
--
13061306
-- @since 0.0.1.9
13071307
--
1308-
mapAccumWithKeyR
1308+
mapAccumRWithKey
13091309
:: MonoidNull v2
13101310
=> (s -> k -> v1 -> (s, v2))
13111311
-> s
13121312
-> MonoidMap k v1
13131313
-> (s, MonoidMap k v2)
1314-
mapAccumWithKeyR f s0 m =
1314+
mapAccumRWithKey f s0 m =
13151315
(coerce
13161316
:: ((k -> v1 -> StateR s v2 ) -> MM k v1 -> StateR s (MM k v2))
13171317
-> ((k -> v1 -> s -> (s, v2)) -> MM k v1 -> s -> (s, MM k v2))
13181318
)
13191319
traverseWithKey (\k v1 s -> f s k v1) m s0
1320-
{-# INLINE mapAccumWithKeyR #-}
1320+
{-# INLINE mapAccumRWithKey #-}
13211321

13221322
--------------------------------------------------------------------------------
13231323
-- Comparison

src/public/Data/MonoidMap.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ module Data.MonoidMap
8080
, traverse
8181
, traverseWithKey
8282
, mapAccumL
83+
, mapAccumLWithKey
8384
, mapAccumR
84-
, mapAccumWithKeyL
85-
, mapAccumWithKeyR
85+
, mapAccumRWithKey
8686

8787
-- * Monoidal operations
8888

src/test/Data/MonoidMap/TraversalSpec.hs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,22 @@ specFor = makeSpec $ do
9696
prop_mapAccumR @String
9797
@k @v & property
9898

99-
describe "mapAccumWithKeyL" $ do
99+
describe "mapAccumLWithKey" $ do
100100

101-
it "prop_mapAccumWithKeyL_@Int" $
102-
prop_mapAccumWithKeyL @Int
101+
it "prop_mapAccumLWithKey_@Int" $
102+
prop_mapAccumLWithKey @Int
103103
@k @v & property
104-
it "prop_mapAccumWithKeyL_@String" $
105-
prop_mapAccumWithKeyL @String
104+
it "prop_mapAccumLWithKey_@String" $
105+
prop_mapAccumLWithKey @String
106106
@k @v & property
107107

108-
describe "mapAccumWithKeyR" $ do
108+
describe "mapAccumRWithKey" $ do
109109

110-
it "prop_mapAccumWithKeyR_@Int" $
111-
prop_mapAccumWithKeyR @Int
110+
it "prop_mapAccumRWithKey_@Int" $
111+
prop_mapAccumRWithKey @Int
112112
@k @v & property
113-
it "prop_mapAccumWithKeyR_@String" $
114-
prop_mapAccumWithKeyR @String
113+
it "prop_mapAccumRWithKey_@String" $
114+
prop_mapAccumRWithKey @String
115115
@k @v & property
116116

117117
prop_traverse
@@ -158,25 +158,25 @@ prop_mapAccumR (applyFun2 -> f) s m =
158158
===
159159
fmap MonoidMap.fromMap (Traversable.mapAccumR f s (MonoidMap.toMap m))
160160

161-
prop_mapAccumWithKeyL
161+
prop_mapAccumLWithKey
162162
:: forall s k v. (Test k v, Eq s, Show s)
163163
=> Fun (s, k, v) (s, v)
164164
-> s
165165
-> MonoidMap k v
166166
-> Property
167-
prop_mapAccumWithKeyL (applyFun3 -> f) s m =
168-
MonoidMap.mapAccumWithKeyL f s m
167+
prop_mapAccumLWithKey (applyFun3 -> f) s m =
168+
MonoidMap.mapAccumLWithKey f s m
169169
===
170170
fmap MonoidMap.fromMap (Map.mapAccumWithKey f s (MonoidMap.toMap m))
171171

172-
prop_mapAccumWithKeyR
172+
prop_mapAccumRWithKey
173173
:: forall s k v. (Test k v, Eq s, Show s)
174174
=> Fun (s, k, v) (s, v)
175175
-> s
176176
-> MonoidMap k v
177177
-> Property
178-
prop_mapAccumWithKeyR (applyFun3 -> f) s m =
179-
MonoidMap.mapAccumWithKeyR f s m
178+
prop_mapAccumRWithKey (applyFun3 -> f) s m =
179+
MonoidMap.mapAccumRWithKey f s m
180180
===
181181
fmap MonoidMap.fromMap (Map.mapAccumRWithKey f s (MonoidMap.toMap m))
182182

src/test/Examples/RecoveredMapSpec.hs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -207,19 +207,19 @@ specFor keyType valueType = do
207207
@k @v @v & property
208208

209209
describe "MapAccumWithKeyL" $ do
210-
it "prop_mapAccumWithKeyL @Int" $
211-
prop_mapAccumWithKeyL @Int
210+
it "prop_mapAccumLWithKey @Int" $
211+
prop_mapAccumLWithKey @Int
212212
@k @v @v & property
213-
it "prop_mapAccumWithKeyL @String" $
214-
prop_mapAccumWithKeyL @String
213+
it "prop_mapAccumLWithKey @String" $
214+
prop_mapAccumLWithKey @String
215215
@k @v @v & property
216216

217217
describe "MapAccumWithKeyR" $ do
218-
it "prop_mapAccumWithKeyR @Int" $
219-
prop_mapAccumWithKeyR @Int
218+
it "prop_mapAccumRWithKey @Int" $
219+
prop_mapAccumRWithKey @Int
220220
@k @v @v & property
221-
it "prop_mapAccumWithKeyR @String" $
222-
prop_mapAccumWithKeyR @String
221+
it "prop_mapAccumRWithKey @String" $
222+
prop_mapAccumRWithKey @String
223223
@k @v @v & property
224224

225225
--------------------------------------------------------------------------------
@@ -534,33 +534,33 @@ prop_mapAccumR (applyFun2 -> f) s0 kvs =
534534
-- MapAccumWithKey
535535
--------------------------------------------------------------------------------
536536

537-
prop_mapAccumWithKeyL
537+
prop_mapAccumLWithKey
538538
:: forall s k v1 v2. (Eq s, Eq v2, Ord k, Show k, Show s, Show v2)
539539
=> Fun (s, k, v1) (s, v2)
540540
-> s
541541
-> [(k, v1)]
542542
-> Property
543-
prop_mapAccumWithKeyL (applyFun3 -> f) s0 kvs =
543+
prop_mapAccumLWithKey (applyFun3 -> f) s0 kvs =
544544
(===)
545-
(RMap.toList <$> rmapAccumWithKeyL f s0 (RMap.fromList kvs))
546-
(OMap.toList <$> omapAccumWithKeyL f s0 (OMap.fromList kvs))
545+
(RMap.toList <$> rmapAccumLWithKey f s0 (RMap.fromList kvs))
546+
(OMap.toList <$> omapAccumLWithKey f s0 (OMap.fromList kvs))
547547
where
548-
rmapAccumWithKeyL = RMap.mapAccumWithKeyL
549-
omapAccumWithKeyL = OMap.mapAccumWithKey
548+
rmapAccumLWithKey = RMap.mapAccumLWithKey
549+
omapAccumLWithKey = OMap.mapAccumWithKey
550550

551-
prop_mapAccumWithKeyR
551+
prop_mapAccumRWithKey
552552
:: forall s k v1 v2. (Eq s, Eq v2, Ord k, Show k, Show s, Show v2)
553553
=> Fun (s, k, v1) (s, v2)
554554
-> s
555555
-> [(k, v1)]
556556
-> Property
557-
prop_mapAccumWithKeyR (applyFun3 -> f) s0 kvs =
557+
prop_mapAccumRWithKey (applyFun3 -> f) s0 kvs =
558558
(===)
559-
(RMap.toList <$> rmapAccumWithKeyR f s0 (RMap.fromList kvs))
560-
(OMap.toList <$> omapAccumWithKeyR f s0 (OMap.fromList kvs))
559+
(RMap.toList <$> rmapAccumRWithKey f s0 (RMap.fromList kvs))
560+
(OMap.toList <$> omapAccumRWithKey f s0 (OMap.fromList kvs))
561561
where
562-
rmapAccumWithKeyR = RMap.mapAccumWithKeyR
563-
omapAccumWithKeyR = OMap.mapAccumRWithKey
562+
rmapAccumRWithKey = RMap.mapAccumRWithKey
563+
omapAccumRWithKey = OMap.mapAccumRWithKey
564564

565565
--------------------------------------------------------------------------------
566566
-- Arbitrary instances

0 commit comments

Comments
 (0)