A
- The raw type of the value that this key maps to inside an HMap
B
- The mapped type of the value that this key maps to inside an HMap
public interface TypeSafeKey<A,B> extends Iso.Simple<A,B>
HMap
s. Additionally, every TypeSafeKey
is an
Iso
from the type the value is stored as to the type it's viewed and set as (on the way in / on the way out).
This allows multiple keys to map to the same value, but to view the value as different types.
This is intentionally an interface so user-defined implementations are possible; however, it's important to note
that all hopes of type-safety hinge on equality being implemented such that no two TypeSafeKey
s with
differing value-type parameters may be considered equal. Reference equality is used here as the default, as that is
sufficient.
Modifier and Type | Interface and Description |
---|---|
static interface |
TypeSafeKey.Simple<A>
|
Modifier and Type | Method and Description |
---|---|
default <C> TypeSafeKey<A,C> |
andThen(Iso.Simple<B,C> f)
Left-to-right composition of this
TypeSafeKey with some other Iso . |
default <U> TypeSafeKey<A,B> |
discardR(Applicative<U,Iso<A,?,B,B>> appB)
Sequence both this
Applicative and appB , discarding appB's result and
returning this Applicative . |
static <A> TypeSafeKey.Simple<A> |
typeSafeKey()
Static factory method for creating a simple type-safe key
|
adapt, andThen, compose, compose, mirror, toLens
andThen, compose, contraMap, diMap, diMapL, diMapR, discardL, flatMap, fmap, iso, iso, mapA, mapB, mapS, mapT, pure, pureIso, simpleIso, trampolineM, unIso, zip
adapt
apply, monomorphize, optic, reframe
default <U> TypeSafeKey<A,B> discardR(Applicative<U,Iso<A,?,B,B>> appB)
Iso.Simple
Applicative
and appB
, discarding appB's
result and
returning this Applicative
. This is generally useful for sequentially performing side-effects.discardR
in interface Applicative<A,Iso<A,?,B,B>>
discardR
in interface Iso<A,A,B,B>
discardR
in interface Iso.Simple<A,B>
discardR
in interface Monad<A,Iso<A,?,B,B>>
discardR
in interface MonadRec<A,Iso<A,?,B,B>>
U
- the type of appB's parameterappB
- the other Applicativedefault <C> TypeSafeKey<A,C> andThen(Iso.Simple<B,C> f)
TypeSafeKey
with some other Iso
. Because the first parameter
fundamentally represents an already stored value type, this is the only composition that is possible for
TypeSafeKey
, which is why only this (and not Iso.compose(Optic)
) is overridden.
Particularly of note is the fact that values stored at this key are still stored as their original manifest
type, and are not duplicated - which is to say, putting a value at a key, yielding a new key via composition,
and putting a new value at the new key still only results in a single entry in the HMap
. Additionally,
all previous keys involved in the new key's composition are still able to resolve the value in their native type.
andThen
in interface Iso.Simple<A,B>
C
- the new value typef
- the other simple isoTypeSafeKey
static <A> TypeSafeKey.Simple<A> typeSafeKey()
A
- the type of value stored at this key