Interface TypeSafeKey<A,B>
- Type Parameters:
A
- The raw type of the value that this key maps to inside anHMap
B
- The mapped type of the value that this key maps to inside anHMap
- All Superinterfaces:
Applicative<A,
,Iso<A, ?, B, B>> Contravariant<A,
,Profunctor<?, A, Iso<?, ?, B, B>>> Functor<A,
,Iso<A, ?, B, B>> Iso<A,
,A, B, B> Iso.Simple<A,
,B> Monad<A,
,Iso<A, ?, B, B>> MonadRec<A,
,Iso<A, ?, B, B>> Optic<Profunctor<?,
,?, ?>, Functor<?, ?>, A, A, B, B> Optic.Simple<Profunctor<?,
,?, ?>, Functor<?, ?>, A, B> Profunctor<A,
A, Iso<?, ?, B, B>>
- All Known Subinterfaces:
TypeSafeKey.Simple<A>
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.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
-
Method Summary
Modifier and TypeMethodDescriptiondefault <C> TypeSafeKey
<A, C> andThen
(Iso.Simple<B, C> f) Left-to-right composition of thisTypeSafeKey
with some otherIso
.default <U> TypeSafeKey
<A, B> Sequence both thisApplicative
andappB
, discardingappB's
result and returning thisApplicative
.static <A> TypeSafeKey.Simple
<A> Static factory method for creating a simple type-safe keyMethods inherited from interface com.jnape.palatable.lambda.optics.Iso
andThen, compose, contraMap, diMap, diMapL, diMapR, discardL, flatMap, fmap, mapA, mapB, mapS, mapT, pure, trampolineM, unIso, zip
Methods inherited from interface com.jnape.palatable.lambda.optics.Iso.Simple
andThen, compose, compose, mirror, toLens
Methods inherited from interface com.jnape.palatable.lambda.optics.Optic
apply, monomorphize
-
Method Details
-
discardR
Description copied from interface:Iso.Simple
Sequence both thisApplicative
andappB
, discardingappB's
result and returning thisApplicative
. This is generally useful for sequentially performing side-effects.- Specified by:
discardR
in interfaceApplicative<A,
B> - Specified by:
discardR
in interfaceIso<A,
A, B, B> - Specified by:
discardR
in interfaceIso.Simple<A,
B> - Specified by:
discardR
in interfaceMonad<A,
B> - Specified by:
discardR
in interfaceMonadRec<A,
B> - Type Parameters:
U
- the type of appB's parameter- Parameters:
appB
- the other Applicative- Returns:
- this Applicative
-
andThen
Left-to-right composition of thisTypeSafeKey
with some otherIso
. Because the first parameter fundamentally represents an already stored value type, this is the only composition that is possible forTypeSafeKey
, which is why only this (and notIso.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.- Specified by:
andThen
in interfaceIso.Simple<A,
B> - Type Parameters:
C
- the new value type- Parameters:
f
- the other simple iso- Returns:
- the new
TypeSafeKey
-
typeSafeKey
Static factory method for creating a simple type-safe key- Type Parameters:
A
- the type of value stored at this key- Returns:
- a unique type-safe key
-