diff --git a/CHANGELOG.md b/CHANGELOG.md index a4d62a72..344c37d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,9 @@ The changelog is available [on GitHub][2]. Use `foldr` instead of explicit recursion and `toList`. * [#182](https://github.com/kowainik/relude/issues/182): Support GHC-8.8.1. +* [#174](https://github.com/kowainik/relude/issues/187): + Implement `bimapBoth` in `Relude.Extra.Tuple` module, + mark `mapBoth` as DEPRECATED. ## 0.5.0 — Mar 18, 2019 diff --git a/src/Relude/Extra/Bifunctor.hs b/src/Relude/Extra/Bifunctor.hs index 94e269a3..d3176b3d 100644 --- a/src/Relude/Extra/Bifunctor.hs +++ b/src/Relude/Extra/Bifunctor.hs @@ -12,17 +12,31 @@ bar :: IO (a, b) baz :: Maybe (Either a b) qux :: Maybe (a, b) + +doo :: (a, a) +dee :: Either a a @ -} module Relude.Extra.Bifunctor - ( bimapF + ( bimapBoth + , bimapF , firstF , secondF ) where import Relude +{- | Maps a function over both elements of a bifunctor. + +>>> bimapBoth length ("a", "bb") +(1,2) +>>> map (bimapBoth not) [Left True, Right False] +[Left False,Right True] +-} +bimapBoth :: Bifunctor f => (a -> b) -> f a a -> f b b +bimapBoth f = bimap f f +{-# INLINE bimapBoth #-} {- | Fmaps functions for nested bifunctor. Short for @fmap (bimap f g)@. diff --git a/src/Relude/Extra/Tuple.hs b/src/Relude/Extra/Tuple.hs index 7850f8e6..b983cb24 100644 --- a/src/Relude/Extra/Tuple.hs +++ b/src/Relude/Extra/Tuple.hs @@ -63,6 +63,7 @@ mapToSnd f a = (a, f a) -} mapBoth :: (a -> b) -> (a, a) -> (b, b) mapBoth f (a1, a2) = (f a1, f a2) +{-# DEPRECATED mapBoth "Use 'bimapBoth' from 'Relude.Extra.Bifunctor' instead" #-} {-# INLINE mapBoth #-} {- | Apply a function that returns a value inside of a functor,