File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1383,23 +1383,31 @@ mappedPost :: (Monad m, Functor g) => (forall x . f x -> m (g x)) -> Stream f m
13831383mappedPost = mapsMPost
13841384{-# INLINE mappedPost #-}
13851385
1386- {-| Fold streamed items into their monoidal sum
1386+ {-| Map each element of the stream to a monoid, and take the monoidal sum of the results.
13871387
1388- >>> S.mconcat $ S.take 2 $ S.map (Data.Monoid.Last . Just) (S.stdinLn)
1389- first<Enter>
1390- last<Enter>
1391- Last {getLast = Just "last"} :> ()
1388+ >>> S.foldMap Sum $ S.take 2 (S.stdinLn)
1389+ 1<Enter>
1390+ 2<Enter>
1391+ 3<Enter>
1392+ Sum {getSum = 6} :> ()
13921393
13931394 -}
1394-
13951395foldMap :: (Monad m , Monoid w ) => (a -> w ) -> Stream (Of a ) m r -> m (Of w r )
1396- foldMap f = fold (\ acc a -> let ! fa = f $! a in mappend acc fa ) mempty id
1396+ foldMap f = fold (\ ! acc a -> mappend acc (f a) ) mempty id
13971397{-# INLINE foldMap #-}
13981398
13991399foldMap_ :: (Monad m , Monoid w ) => (a -> w ) -> Stream (Of a ) m r -> m w
1400- foldMap_ f = fold_ (\ acc a -> let ! fa = f $! a in mappend acc fa ) mempty id
1400+ foldMap_ f = fold_ (\ ! acc a -> mappend acc (f a) ) mempty id
14011401{-# INLINE foldMap_ #-}
14021402
1403+ {-| Fold streamed items into their monoidal sum
1404+
1405+ >>> S.mconcat $ S.take 2 $ S.map (Data.Monoid.Last . Just) (S.stdinLn)
1406+ first<Enter>
1407+ last<Enter>
1408+ Last {getLast = Just "last"} :> ()
1409+
1410+ -}
14031411mconcat :: (Monad m , Monoid w ) => Stream (Of w ) m r -> m (Of w r )
14041412mconcat = fold mappend mempty id
14051413{-# INLINE mconcat #-}
You can’t perform that action at this time.
0 commit comments