Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Bifunctor

Lean: Hale.Base.Bifunctor | Haskell: Data.Bifunctor

Overview

Typeclass for types with two covariant type parameters. Provides bimap, mapFst, mapSnd.

API Mapping

LeanHaskellKind
Bifunctor classBifunctorTypeclass
bimapbimapMethod
mapFstfirstMethod
mapSndsecondMethod
LawfulBifunctor(lawful)Typeclass

Instances

  • Bifunctor Prod
  • Bifunctor Sum
  • Bifunctor Except
  • LawfulBifunctor Prod
  • LawfulBifunctor Sum
  • LawfulBifunctor Except

Proofs & Guarantees

  • bimap_idbimap id id = id (via LawfulBifunctor)
  • bimap_compbimap (f1 . f2) (g1 . g2) = bimap f1 g1 . bimap f2 g2 (via LawfulBifunctor)

Example

-- Map over both components of a pair
Bifunctor.bimap (· * 10) (· ++ "!") (1, "hello")
-- => (10, "hello!")