Core Combinators
identity
Section titled “identity”Lens that always returns right s. A no-op.
bend.identity.get 42 # right 42compose outer inner
Section titled “compose outer inner”Thread inner through outer. get applies outer then inner; set is the reverse.
pipe [lens ...]
Section titled “pipe [lens ...]”Compose a list of lenses left-to-right. Short-circuits on first left.
bend.pipe [ (bend.attr "x") bend.int ]parse refine lens
Section titled “parse refine lens”Apply refine (a function returning Either) to the focused value of lens.
focus getF setF
Section titled “focus getF setF”Lift pure get/set functions into a lens. getF s must return Either.
iso f g
Section titled “iso f g”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.0prism build match
Section titled “prism build match”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);