S
- The input object type.T
- The output object type.A
- The input field type.B
- The output field type.public interface Affine<S,T,A,B> extends Optic<AffineP _,S::A,T::B>
A
from the input object type S
and to
combine the input S
and the transformed field type B
into the output object type T
.
The canonical example of an affine is retrieving and storing a value in a dynamic key-value store.
In order to be a lawful affine, the implementations of preview(Object)
and set(Object, Object)
must satisfy certain requirements. Assume that the object types S
and T
are implicitly convertible
between each other and that the field types A
and B
are similarly convertible. Then the following
rules must hold (==
here represents logical equality and not reference equality).
set(b2, set(b1, s)) == set(b2, s)
- Setting twice is equivalent to setting once.
preview(update(b, s)) == Right(b)
- Previewing after setting yields the value used to set.
set?(preview(s), s) == s
- Setting with a previewed value yields the original object.
Affine optics that are not lawful are said to be either neutral or chaotic, depending on the degree to which the affine laws are broken.
Modifier and Type | Interface and Description |
---|---|
static class |
Affine.Instance<A2,B2>
|
Modifier and Type | Method and Description |
---|---|
default <P extends K2> |
eval(AffineP P proof)
Evaluates this affine to produce a function that, when given a transformation between field types, produces
a transformation between object types.
|
(T|A) |
preview(S s)
Extracts an optional value from the input object.
|
T |
set(B b,
S s)
Combines the given output field and an input object to produce an output object.
|
compose, composeUnchecked, upCast
(T|A) preview(S s)
The method is analogous to partial getter methods such as Map.get(Object)
.
set(Object, Object)
, satisfy the affine laws
in order for this affine to be a lawful affine.s
- The input object.T set(B b, S s)
preview(Object)
, satisfy the affine laws
in order for this affine to be a lawful affine.b
- A value of the output field type.s
- A value of the input object type.default <P extends K2> (P<A,B>) -> P<S,T> eval(AffineP P proof)
eval
in interface Optic<AffineP _,S::A,T::B>
P
- The type of transformation.proof
- The AffineP
type class instance for the transformation type.Affine.Instance