Proposal: (a -> Bool) -> a -> f a

David Feuer david.feuer at gmail.com
Wed Dec 24 15:46:06 UTC 2014


Or I guess partial could be changed. Whatever.
On Dec 24, 2014 10:33 AM, "Yitzchak Gale" <gale at sefer.org> wrote:

> Nikita Volkov wrote:
> >>> I propose to add the following utility function into
> |Control.Applicative|:
> >>> |cond :: (Alternative f) => (a -> Bool) -> a -> f a
> >>> cond p a = if p a then pure a else empty
>
> Roman Cheplyaka wrote:
> > * guardp (for "predicate")
> > * guardf (for "function")
> > * guardWith
> > I wouldn't be opposed to cond, either.
>
> Oliver Charles wrote:
> > I tend to use `pure` and `mfilter` for this case:
> > \x -> fromMaybe 0 $ mfilter (> 0) $ pure (x - 10)
>
> I reach for this all the time and find it lacking.
> In an attempt to be merciful to some of my readers,
> I avoid Ollie's very nice mfilter solution and refactor
> instead.
>
> +1
>
> Regarding the name - all of the suggestions of
> Nikita and Roman are fine with me. Let's just
> build this bikeshed!
>
> Thanks,
> Yitz
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20141224/6c422d58/attachment.html>


More information about the Libraries mailing list