Skip to content

Commit

Permalink
Implement bimapBoth (#174) (#202)
Browse files Browse the repository at this point in the history
* Implement `bimapBoth` (#174)

* fix style

* notes
  • Loading branch information
astynax authored and vrom911 committed Oct 4, 2019
1 parent 78c307f commit 10a5a78
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 15 additions & 1 deletion src/Relude/Extra/Bifunctor.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)@.
Expand Down
1 change: 1 addition & 0 deletions src/Relude/Extra/Tuple.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 10a5a78

Please sign in to comment.