Lens
Lens:
object
Defined in: Core/Lens.ts:24
Type Declaration
Section titled “Type Declaration”andThen
Section titled “andThen”andThen: <
A,B>(inner) => <S>(outer) =>Lens<S,B>
Composes two Lenses: focuses through the outer, then through the inner. Use in a pipe chain to build up a deep focus step by step.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”Lens<A, B>
Returns
Section titled “Returns”<S>(outer) => Lens<S, B>
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 step in the focus is optional (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>
Example
Section titled “Example”from:
object
from.accessors
Section titled “from.accessors”accessors: <
S,A>(get,set) =>Lens<S,A> =makeAccessors
Constructs a Lens from a getter and a setter.
Type Parameters
Section titled “Type Parameters”S
A
Parameters
Section titled “Parameters”(s) => A
(a) => (s) => S
Returns
Section titled “Returns”Lens<S, A>
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]>
Example
Section titled “Example”get: <
S,A>(lens) => (s) =>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”(s) => A
Example
Section titled “Example”modify
Section titled “modify”modify: <
S,A>(lens) => (f) => (s) =>S
Applies a function to the focused value, returning a new structure.
Type Parameters
Section titled “Type Parameters”S
A
Parameters
Section titled “Parameters”Lens<S, A>
Returns
Section titled “Returns”(f) => (s) => S
Example
Section titled “Example”set: <
S,A>(lens) => (a) => (s) =>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”(a) => (s) => S
Example
Section titled “Example”toOptional
Section titled “toOptional”toOptional: <
S,A>(lens) =>Optional<S,A>
Converts a Lens to an Optional. Every Lens is a valid Optional whose get always returns Some.
Type Parameters
Section titled “Type Parameters”S
A
Parameters
Section titled “Parameters”Lens<S, A>
Returns
Section titled “Returns”Optional<S, A>