<div dir="ltr"><div dir="ltr"><div dir="ltr">On Tue, May 7, 2019 at 11:49 PM Isaac Elliott <<a href="mailto:isaace71295@gmail.com">isaace71295@gmail.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">I've previously suggested similar things, like:<div dir="auto"><br></div><div dir="auto"><span style="font-family:sans-serif;font-size:12.8px">allA :: (Applicative f, Foldable t) => (a -> f Bool) -> t a -> f Bool</span><br style="font-family:sans-serif;font-size:12.8px"><span style="font-family:sans-serif;font-size:12.8px">allA f = fmap getAll . getAp . foldMap (Ap . fmap All . f)</span></div><br><span style="font-family:sans-serif">I think such functions are very convenient.</span></div></blockquote><div><br></div><div>I think your allA is arguably better-justified than foldMapA because the simple</div><div>implementation you demonstrate could run into trouble if fmap is expensive. Better:</div><div><br></div><div><div>allA :: (Applicative f, Foldable t) => (a -> f Bool) -> t a -> f Bool</div><div>allA f = getFall . foldMap (Fall . f)</div><div><br></div><div>newtype Fall f = Fall {getFall :: f Bool}</div><div>instance Applicative f => Semigroup (Fall f) where</div><div>  Fall x <> Fall y = Fall $ liftA2 (&&) x y</div><div>instance Applicative f => Monoid (Fall f) where</div><div>  mempty = Fall (pure True)</div></div><div><br></div><div>I keep wondering if there's some nice way (short of Coyoneda or similar) to generalize this</div><div>sort of thing. I haven't thought of one yet.</div></div></div></div>