ndmitchell / extra

Extra Haskell functions
Other
94 stars 37 forks source link

Add some conversions in Data.Function #60

Open infinity0 opened 4 years ago

infinity0 commented 4 years ago

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

infinity0 commented 4 years ago

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

ndmitchell commented 4 years ago

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.