extra icon indicating copy to clipboard operation
extra copied to clipboard

Add some conversions in Data.Function

Open infinity0 opened this issue 4 years ago • 2 comments

Useful for adapting with libraries that provide utilities expecting particular function shapes, but not others.

infinity0 avatar May 30 '20 10:05 infinity0

That's fair enough, so far I'm only using these in some unpublished personal projects but I thought these might be useful elsewhere. I've seen various cases of functions taking state-transition functions e.g. state, stateTVar (although granted I wrote this), atomicModifyIORef, alterF. Usually they provide some other function for the get/set versions but it's annoying having to remember all the names.

In the meantime though, I also realise that (.:) :: (c -> d) -> (a -> b -> c) -> (a -> b -> d) could be useful here, do you agree? The other libraries that already include this function, seem not as well-polished as this one, so I'd rather not incur an extra dependency. g .: f is slightly clearer than (g .) . f

infinity0 avatar May 31 '20 10:05 infinity0

My usual inclination is to build the state ignoring stuff into the function directly. E.g. atomicModifyIORef_ doesn't require returning a redundant (). I think composing these things in is cute, but not necessarily more readable, whereas atomicModifyIORef_ is nice and simple.

Separately, (.:) seems well suited to Data.Function.Extra.

ndmitchell avatar May 31 '20 11:05 ndmitchell