Lens
Lens:
object
Defined in: Core/Lens.ts:31
Utilities for reading, overwriting, and transforming values within data structures via composable bidirectional lenses.
Type Declaration
Section titled “Type Declaration”andThen
Section titled “andThen”andThen: <
A,B>(inner) => <S>(outer) =>Lens<S,B>
Composes two lenses to focus sequentially through nested structures.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”Lens<A, B>
Returns
Section titled “Returns”<S>(outer) => Lens<S, B>
Lens.andThenOptional to compose a Lens with an Optional path.
Example
Section titled “Example”andThenOptional
Section titled “andThenOptional”andThenOptional: <
A,B>(inner) => <S>(outer) =>Optional<S,B>
Composes a Lens with an Optional, producing an Optional. Use when the next segment in the path may be absent.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”Optional<A, B>
Returns
Section titled “Returns”<S>(outer) => Optional<S, B>
Lens.andThen to compose two guaranteed Lens paths.
Example
Section titled “Example”from:
object
Constructors for creating Lens instances from accessors or property keys.
from.accessors
Section titled “from.accessors”accessors: <
S,A>(get,set) =>Lens<S,A> =makeAccessors
Constructs a Lens from getter and setter functions.
Type Parameters
Section titled “Type Parameters”S
A
Parameters
Section titled “Parameters”(structure) => A
(value) => (structure) => S
Returns
Section titled “Returns”Lens<S, A>
Lens.from.property to create a Lens focused on an object property.
Example
Section titled “Example”from.property
Section titled “from.property”property: <
S>() => <K>(key) =>Lens<S,S[K]> =makeProperty
Creates a Lens that focuses on a property of an object. Call with the structure type first, then the key.
Type Parameters
Section titled “Type Parameters”S
Returns
Section titled “Returns”<K>(key) => Lens<S, S[K]>
Lens.from.accessors to construct a Lens from custom getter and setter functions.
Example
Section titled “Example”get: <
S,A>(lens) => (structure) =>A
Reads the focused value from a structure.
Type Parameters
Section titled “Type Parameters”S
A
Parameters
Section titled “Parameters”Lens<S, A>
Returns
Section titled “Returns”(structure) => A
- Lens.set to replace the focused value.
- Lens.modify to transform the focused value with a function.
Example
Section titled “Example”modify
Section titled “modify”modify: <
S,A>(lens) => (transform) => (structure) =>S
Applies a function to the focused value, returning a new structure. Preserves the original structure reference if the transformed value is identical.
Type Parameters
Section titled “Type Parameters”S
A
Parameters
Section titled “Parameters”Lens<S, A>
Returns
Section titled “Returns”(transform) => (structure) => S
Example
Section titled “Example”set: <
S,A>(lens) => (value) => (structure) =>S
Replaces the focused value within a structure, returning a new structure.
Type Parameters
Section titled “Type Parameters”S
A
Parameters
Section titled “Parameters”Lens<S, A>
Returns
Section titled “Returns”(value) => (structure) => S
- Lens.get to extract the focused value.
- Lens.modify to transform the focused value with a function.
Example
Section titled “Example”to:
object
Converters from Lens to wider optic representations.
to.Optional
Section titled “to.Optional”Optional: <
S,A>(lens) =>Optional<S,A>
Converts a Lens to an Optional whose getter always yields Some.
Type Parameters
Section titled “Type Parameters”S
A
Parameters
Section titled “Parameters”Lens<S, A>
Returns
Section titled “Returns”Optional<S, A>
Lens.andThenOptional to compose directly with an Optional without manual conversion.