extra icon indicating copy to clipboard operation
extra copied to clipboard

Add applyWhen :: Bool -> (a -> a) -> a -> a

Open erikryb opened this issue 5 years ago • 3 comments

Consider adding applyWhen from here.

erikryb avatar Jun 12 '20 14:06 erikryb

That doesn't seem unreasonable. I guess Data.Function.Extra would be the right place?

ndmitchell avatar Jun 12 '20 20:06 ndmitchell

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.

andreasabel avatar Feb 02 '21 23:02 andreasabel

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.

ndmitchell avatar Feb 03 '21 08:02 ndmitchell

This is in base now.

georgefst avatar Jan 06 '24 23:01 georgefst

@erikryb Please close.

andreasabel avatar Jan 07 '24 11:01 andreasabel

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.

ndmitchell avatar Jan 14 '24 14:01 ndmitchell

Isn't there base-compat for such purposes?

andreasabel avatar Jan 14 '24 15:01 andreasabel

Yep, but extra also provides some level of base-compat, just not total. Often for things that started in extra library.

ndmitchell avatar Jan 14 '24 17:01 ndmitchell