Applicative-based definitions in Data.Foldable

Isaac Elliott isaace71295 at gmail.com
Thu Jan 24 11:04:02 UTC 2019


I used `anyA` today, to run predicates on things contained in IORefs.

On Fri, Dec 21, 2018 at 10:37 AM Isaac Elliott <isaace71295 at gmail.com>
wrote:

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20190124/4dcffa2d/attachment.html>


More information about the Libraries mailing list