Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Data/Foldable/Extra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Data.Foldable.Extra
) where

import Data.Foldable
import Data.Monoid (Ap(..))
import qualified Control.Monad.Extra as MX

-- | Composition of 'not' and 'null'
Expand Down Expand Up @@ -69,3 +70,7 @@ firstJustM p = MX.firstJustM p . toList
-- > compareLength (1:2:3:undefined) 2 == GT
compareLength :: Foldable f => f a -> Int -> Ordering
compareLength = foldr (\_ acc n -> if n > 0 then acc (n - 1) else GT) (compare 0)

-- | A generalization of 'Control.Monad.Extra.concatMapM', 'anyM', 'allM', etc., to an aribtrary 'Monoid'.
foldMapM :: (Foldable f, Applicative m, Monoid b) => (a -> m b) -> f a -> m b
foldMapM f = getAp . foldMap (Ap . f)