ndmitchell / extra

Extra Haskell functions
Other
93 stars 37 forks source link

suggestion: mwhen :: Monoid a => Bool -> a -> a #102

Closed juhp closed 1 year ago

juhp commented 1 year ago

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.)

ndmitchell commented 1 year ago

Yep, here seems like a reasonable step before it ends up in CLC. And the naming makes sense.

ndmitchell commented 1 year ago

Released as 1.7.13

juhp commented 1 year ago

Thank you!