Skip to content

Core Combinators

Lens that always returns right s. A no-op.

bend.identity.get 42 # right 42

Thread inner through outer. get applies outer then inner; set is the reverse.

Compose a list of lenses left-to-right. Short-circuits on first left.

bend.pipe [ (bend.attr "x") bend.int ]

Apply refine (a function returning Either) to the focused value of lens.

Lift pure get/set functions into a lens. getF s must return Either.

Isomorphism. get = right ∘ f; set ignores the source and applies g.

let celsius = bend.iso (f: (f - 32.0) / 1.8) (c: c * 1.8 + 32.0);
in celsius.get 212.0 # right 100.0
celsius.set 0 100.0 # right 212.0

Sum-type focus. match s returns right a for the focused variant or left s for wrong variant. build a reconstructs.

let gitUrl = bend.prism
(url: { type = "git"; inherit url; })
(s: if s.type or "" == "git" then bend.right s.url else bend.left s);
Contribute Community Sponsor