extra
extra copied to clipboard
Add applyWhen :: Bool -> (a -> a) -> a -> a
That doesn't seem unreasonable. I guess Data.Function.Extra would be the right place?
Identical function defined at http://hackage.haskell.org/package/Agda-2.6.1/docs/Agda-Utils-Function.html#v:applyWhen. Also defines applyUnless and monadic variants.
I think I'd stick to just applyWhen for now - the monadic variants look a little weird (they take a monadic argument to a function, which is odd). Patch welcome if someone wants to create Data.Function.Extra with it.
This is in base now.
@erikryb Please close.
Closing it. Given it's in base, I would be happy to include a patch backporting applyWhen to older versions of GHC in Data.Function.Extra.
Isn't there base-compat for such purposes?
Yep, but extra also provides some level of base-compat, just not total. Often for things that started in extra library.