24 Dec
2014
24 Dec
'14
10:33 a.m.
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