
20 Dec
2018
20 Dec
'18
8:22 p.m.
With the introduction of the 'Ap' monoid in base-4.13, it seems like Applicative based definitions for common folds would be appropriate in base. For example:
allA :: (Applicative f, Foldable t) => (a -> f Bool) -> t a -> f Bool allA f = fmap getAll . getAp . foldMap (Ap . fmap All . f)
all :: Foldable t => (a -> Bool) -> t a -> Bool all f = runIdentity . allA (Identity . f)
I've personally written the Applicative version in everyday code. Thoughts? Isaac