S
- The input object type.T
- The output object type.A
- The input field type.B
- The output field type.public interface Adapter<S,T,A,B> extends Optic<Profunctor _,S::A,T::B>
A
from the input object S
and to create an output object T
from an output field B
.
The canonical example of an adapter is boxing and unboxing.
In order to be a lawful adapter, the implementations of from(Object)
and to(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).
from(to(b)) == b
- Round-tripping a field yields the input.
to(from(s)) == s
- Round-tripping an object yields the input.
Adapter optics that are not lawful are said to be either neutral or chaotic, depending on the degree to which the adapter laws are broken.
Prism
, and is sometimes called an Iso
.Modifier and Type | Interface and Description |
---|---|
static class |
Adapter.Instance<A2,B2>
The
Profunctor type class instance for Adapter . |
Modifier and Type | Method and Description |
---|---|
default <P extends K2> |
eval(Profunctor P proofBox)
Evaluates this adapter to produce a function that, when given a transformation between field types, produces
a transformation between object types.
|
A |
from(S s)
Unboxes a value from the input object.
|
T |
to(B b)
Boxes a value into an output object.
|
compose, composeUnchecked, upCast
A from(S s)
to(Object)
, satisfy the adapter laws
in order for this adapter to be a lawful adapter.s
- A value of the input object type.T to(B b)
from(Object)
, satisfy the adapter laws
in order for this adapter to be a lawful adapter.b
- A value of the output field type.default <P extends K2> (P<A,B>) -> P<S,T> eval(Profunctor P proofBox)
eval
in interface Optic<Profunctor _,S::A,T::B>
P
- The type of transformation.proofBox
- The Profunctor
type class instance for the transformation type.Adapter.Instance