cat/instances/bifunctor
Bifunctor
instances: Tuple, Pair, and Either.
Values
pub fn either_bifunctor(
,
) -> bifunctor.Bifunctor(
types.EitherBF,
a,
b,
c,
d,
cat.Either(a, b),
cat.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.Bifunctor(
types.PairBF,
a,
b,
c,
d,
cat.Pair(a, b),
cat.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.Bifunctor(
types.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")