
On Tue, May 7, 2019 at 11:49 PM Isaac Elliott
I've previously suggested similar things, like:
allA :: (Applicative f, Foldable t) => (a -> f Bool) -> t a -> f Bool allA f = fmap getAll . getAp . foldMap (Ap . fmap All . f)
I think such functions are very convenient.
I think your allA is arguably better-justified than foldMapA because the simple implementation you demonstrate could run into trouble if fmap is expensive. Better: allA :: (Applicative f, Foldable t) => (a -> f Bool) -> t a -> f Bool allA f = getFall . foldMap (Fall . f) newtype Fall f = Fall {getFall :: f Bool} instance Applicative f => Semigroup (Fall f) where Fall x <> Fall y = Fall $ liftA2 (&&) x y instance Applicative f => Monoid (Fall f) where mempty = Fall (pure True) I keep wondering if there's some nice way (short of Coyoneda or similar) to generalize this sort of thing. I haven't thought of one yet.