Skip to content

Bifunctors

Map both branches of the lens result.

  • fL applied to left; fR applied to right
  • set is unchanged (only get transforms)
(bend.bimap (_: "err") (x: x * 2) bend.int).get 5
# right 10
(bend.bimap (_: "err") (x: x * 2) bend.int).get "bad"
# left "err"

Map left branch only; pass right unchanged.

(bend.lmap (_: "replaced") bend.int).get "bad"
# left "replaced"
(bend.lmap (_: "replaced") bend.int).get 42
# right 42

Map right branch only; pass left unchanged.

(bend.rmap (x: x + 1) bend.int).get 5
# right 6
(bend.rmap (x: x + 1) bend.int).get "bad"
# left "bad"
Contribute Community Sponsor