Lately I have been wanting this regularly and feel it would make a good addition to extra:
mwhen :: Monoid a => Bool -> a -> a
mwhen b x = if b then x else mempty
I would mostly use it for strings: "string" ++ mwhen cond "-suffix"
The name comes from dminuoso, on #haskell.
After discussion there, Hecate suggested I propose it here
(rather than straight to CLC), and I agreed that makes sense, so here I am. :-)
(Though it might still be worth adding to Data.Monoid someday.)
Lately I have been wanting this regularly and feel it would make a good addition to extra:
I would mostly use it for strings:
"string" ++ mwhen cond "-suffix"
The name comes from dminuoso, on #haskell. After discussion there, Hecate suggested I propose it here (rather than straight to CLC), and I agreed that makes sense, so here I am. :-) (Though it might still be worth adding to Data.Monoid someday.)