Interface TypeSafeKey<A,B>
-
- Type Parameters:
A- The raw type of the value that this key maps to inside anHMapB- 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>
public interface TypeSafeKey<A,B> extends Iso.Simple<A,B>
An interface representing a parametrized key for use inHMaps. Additionally, everyTypeSafeKeyis anIsofrom 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
TypeSafeKeys 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 Classes Modifier and Type Interface Description static interfaceTypeSafeKey.Simple<A>
-
Method Summary
All Methods Static Methods Instance Methods Default Methods Modifier and Type Method Description default <C> TypeSafeKey<A,C>andThen(Iso.Simple<B,C> f)Left-to-right composition of thisTypeSafeKeywith some otherIso.default <U> TypeSafeKey<A,B>discardR(Applicative<U,Iso<A,?,B,B>> appB)Sequence both thisApplicativeandappB, discardingappB'sresult and returning thisApplicative.static <A> TypeSafeKey.Simple<A>typeSafeKey()Static factory method for creating a simple type-safe key-
Methods 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 Detail
-
discardR
default <U> TypeSafeKey<A,B> discardR(Applicative<U,Iso<A,?,B,B>> appB)
Description copied from interface:Iso.SimpleSequence both thisApplicativeandappB, discardingappB'sresult and returning thisApplicative. This is generally useful for sequentially performing side-effects.- Specified by:
discardRin interfaceApplicative<A,B>- Specified by:
discardRin interfaceIso<A,A,B,B>- Specified by:
discardRin interfaceIso.Simple<A,B>- Specified by:
discardRin interfaceMonad<A,B>- Specified by:
discardRin interfaceMonadRec<A,B>- Type Parameters:
U- the type of appB's parameter- Parameters:
appB- the other Applicative- Returns:
- this Applicative
-
andThen
default <C> TypeSafeKey<A,C> andThen(Iso.Simple<B,C> f)
Left-to-right composition of thisTypeSafeKeywith 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:
andThenin interfaceIso.Simple<A,B>- Type Parameters:
C- the new value type- Parameters:
f- the other simple iso- Returns:
- the new
TypeSafeKey
-
typeSafeKey
static <A> TypeSafeKey.Simple<A> 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
-
-