Bifunctor
Lean: Hale.Base.Bifunctor | Haskell: Data.Bifunctor
Overview
Typeclass for types with two covariant type parameters. Provides bimap, mapFst, mapSnd.
API Mapping
| Lean | Haskell | Kind |
|---|---|---|
Bifunctor class | Bifunctor | Typeclass |
bimap | bimap | Method |
mapFst | first | Method |
mapSnd | second | Method |
LawfulBifunctor | (lawful) | Typeclass |
Instances
Bifunctor ProdBifunctor SumBifunctor ExceptLawfulBifunctor ProdLawfulBifunctor SumLawfulBifunctor Except
Proofs & Guarantees
bimap_id—bimap id id = id(viaLawfulBifunctor)bimap_comp—bimap (f1 . f2) (g1 . g2) = bimap f1 g1 . bimap f2 g2(viaLawfulBifunctor)
Example
-- Map over both components of a pair
Bifunctor.bimap (· * 10) (· ++ "!") (1, "hello")
-- => (10, "hello!")