Skip to content

The adapt Primitive

The sole primitive everything composes from.

Parameters:

  • 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)
  • lens — inner lens to apply to the focused value

Returns: A lens with get and set operations.

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

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