File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -262,6 +262,9 @@ module Data.Map.Internal (
262
262
, foldrWithKey'
263
263
, foldlWithKey'
264
264
265
+ -- ** Strict monadic folds
266
+ , foldlWithKeyM'
267
+
265
268
-- * Conversion
266
269
, elems
267
270
, keys
@@ -3362,6 +3365,17 @@ foldlWithKey' f z = go z
3362
3365
in go (f z'' kx x) r
3363
3366
{-# INLINE foldlWithKey' #-}
3364
3367
3368
+ -- | /O(n)/. Monadic variant of 'foldlWithKey\''.
3369
+ foldlWithKeyM' :: Monad m => (a -> k -> b -> m a ) -> a -> Map k b -> m a
3370
+ foldlWithKeyM' f z = go z
3371
+ where
3372
+ go ! z' Tip = return z'
3373
+ go z' (Bin _ kx x l r) = do
3374
+ ! z'' <- go z' l
3375
+ z''' <- f z'' kx x
3376
+ go z''' r
3377
+ {-# INLINE foldlWithKeyM' #-}
3378
+
3365
3379
-- | /O(n)/. Fold the keys and values in the map using the given monoid, such that
3366
3380
--
3367
3381
-- @'foldMapWithKey' f = 'Prelude.fold' . 'mapWithKey' f@
You can’t perform that action at this time.
0 commit comments