cat/instances/bifunctor

Bifunctor instances: Tuple, Pair, and Either.

Types

Phantom type for Either Bifunctor.

pub type EitherBF

Phantom type for Pair Bifunctor.

pub type PairBF

Phantom type for Tuple Bifunctor.

pub type TupleBF

Functions

pub fn either_bifunctor() -> Bifunctor(
  EitherBF,
  a,
  b,
  c,
  d,
  Either(a, b),
  Either(c, d),
)

Either Bifunctor.

Examples

let show_or_double = either_bifunctor().bimap(int.to_string, fn(x) { x * 2 })

Left(10)
|> show_or_double()
// -> should.equal(cat.Left("10"))
Right(10)
|> show_or_double()
// -> Right(20)
pub fn pair_bifunctor() -> Bifunctor(
  PairBF,
  a,
  b,
  c,
  d,
  Pair(a, b),
  Pair(c, d),
)

Pair Bifunctor.

Examples

Pair(2, 3)
|> pair_bifunctor().bimap(fn(x) { x % 3 }, int.to_string)()
// -> Pair(2, "3")
pub fn tuple_bifunctor() -> Bifunctor(
  TupleBF,
  a,
  b,
  c,
  d,
  #(a, b),
  #(c, d),
)

Tuple Bifunctor.

Examples

#(6, False)
|> tuple_bifunctor().bimap(fn(x) { [x] }, fn(b) { bool.to_string(b) })()
// -> #([6], "False")
Search Document