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 (
262262 , foldrWithKey'
263263 , foldlWithKey'
264264
265+ -- ** Strict monadic folds
266+ , foldlWithKeyM'
267+
265268 -- * Conversion
266269 , elems
267270 , keys
@@ -3362,6 +3365,17 @@ foldlWithKey' f z = go z
33623365 in go (f z'' kx x) r
33633366{-# INLINE foldlWithKey' #-}
33643367
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+
33653379-- | /O(n)/. Fold the keys and values in the map using the given monoid, such that
33663380--
33673381-- @'foldMapWithKey' f = 'Prelude.fold' . 'mapWithKey' f@
You can’t perform that action at this time.
0 commit comments