HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulerelude-1.2.0.0Haskell2010

Relude.Extra.Bifunctor

SPDX-License-Identifier : MIT Maintainer : Kowainik xrom.xkov@gmail.com Stability : Stable Portability : Portable

Useful combinators for bifunctors inside functors. This set of functions is useful when you want to work with types like these ones:

foo :: IO (Either a b)
bar :: IO (a, b)

baz :: Maybe (Either a b)
qux :: Maybe (a, b)

doo :: (a, a)
dee :: Either a a
  • 4 values
  • Packagerelude-1.2.0.0
  • Exports4
  • LanguageHaskell2010
  • LicenceMIT
  • SourceBifunctor.hs
valuebimapBoth :: Bifunctor f => (a -> b) -> f a a -> f b b
#

Maps a function over both elements of a bifunctor.

Example2 expressions
bimapBoth length ([True], [False, True])(1,2)map (bimapBoth not) [Left True, Right False][Left False,Right True]
valuebimapF
  1. :: (Functor f, Bifunctor p)
  2. => a -> c
  3. -> b -> d
  4. -> f (p a b)
  5. -> f (p c d)
#

Fmaps functions for nested bifunctor. Short for fmap (bimap f g).

Example1 expression
bimapF not length $ Just (False, ['a', 'b'])Just (True,2)
valuefirstF :: (Functor f, Bifunctor p) => (a -> c) -> f (p a b) -> f (p c b)
#

Short for fmap . first.

Example1 expression
firstF not $ Just (False, ['a', 'b'])Just (True,"ab")
valuesecondF :: (Functor f, Bifunctor p) => (b -> d) -> f (p a b) -> f (p a d)
#

Short for fmap . second.

Example1 expression
secondF length  $ Just (False, ['a', 'b'])Just (False,2)