Proposal: Add Data.Monoid.mwhen :: Monoid m => Bool -> m -> m

Mario Blažević mblazevic at stilo.com
Wed Apr 10 18:04:35 UTC 2019


On 2019-04-10 11:36 a.m., James Ashwell wrote:
> This would mimic the behaviour of Control.Monad.when for monoids rather 
> than applicatives.
> 
> mwhen :: Monoid m => Bool -> m -> m
> 
> mwhen b a
> | b         = a
> | otherwise = mempty

Or shorter

mwhen = bool (const mempty) id

I'd rather construct the right-hand side than memorize the left, so -1 
from me.


More information about the Libraries mailing list