o optics v2.0.0
Docs menu
Concepts Optic Kinds

Optic Kinds

An optic describes a relationship between a source type S and a focused target type A.

The kind tells you what operations are lawful.

KindCardinalityWritableUse it for
Lens<S, A>exactly oneyesrequired fields
Prism<S, A>zero or oneyesoptional fields, union branches
Iso<S, A>exactly oneyesinvertible representations
Traversal<S, A>zero or moreyesarrays and repeated focuses
Getter<S, A>exactly onenoderived values
Fold<S, A>zero or morenoread-only extraction

Total Vs Partial

A Lens is total. If you have a Lens<Person, string>, you can always get a string from a Person.

A Prism is partial. If you have a Prism<Person, Address>, get may return undefined.

const result = addressPrism.get(person)
// Address | undefined

Writable Vs Read-Only

Getter and Fold deliberately have no write operations. Once a read-only optic enters composition, the result is read-only too.

This is not a limitation. It is the type system preventing you from setting a computed value and calling it a plan.