Skip to content

The adapt Primitive

The sole primitive everything composes from.

Parameters:

  • lens — inner lens to apply to the focused value
  • from — extract inner source from outer (must return Either)
  • back — write inner result back into outer state
  • refine — transform the focused value (must return Either)

Returns: A lens with get and set operations.

adapt identity (s: s.x) (s: v: s // { x = v; }) (v: bend.right (v + 1))

How it works:

get extracts via from, applies lens.get, then applies refine. set extracts via from, applies lens.set, writes back via back.

All other combinators in Bend — pipe, record, each, alt, attr — are built from adapt.

Contribute Community Sponsor