serokell / universum

:milky_way: Prelude written in @Serokell
MIT License
176 stars 28 forks source link

Add 'Bifunctor' functions that automatically work for 'Bifunctor' inside 'Functor' #151

Open chshersh opened 6 years ago

chshersh commented 6 years ago

Sometimes it's convenient to map bimap and related functions inside some Functor. For example, if your data base returns Either inside IO. It might be slightly les convenient to write fmap . first f. So I propose to add these functions:

bimapF  :: (Functor f, Bifunctor p) => (a -> c) -> (b -> d) -> f (p a b) -> f (p c d)
firstF  :: ... similar
secondF :: ... similar

I feel that serokell-util might be a better place for such functions. But names are unambiguos so let's see what others think.