Class Tagged<S,B>
- java.lang.Object
-
- com.jnape.palatable.lambda.functor.builtin.Tagged<S,B>
-
- Type Parameters:
S
- the phantom typeB
- the value type
- All Implemented Interfaces:
Applicative<B,Tagged<S,?>>
,Cocartesian<S,B,Tagged<?,?>>
,Contravariant<S,Profunctor<?,B,Tagged<?,?>>>
,Functor<B,Tagged<S,?>>
,Profunctor<S,B,Tagged<?,?>>
,Monad<B,Tagged<S,?>>
,MonadRec<B,Tagged<S,?>>
,Traversable<B,Tagged<S,?>>
public final class Tagged<S,B> extends java.lang.Object implements MonadRec<B,Tagged<S,?>>, Traversable<B,Tagged<S,?>>, Cocartesian<S,B,Tagged<?,?>>
LikeConst
, but the phantom parameter is in the contravariant position, and the value is in covariant position.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <C> Tagged<Choice2<C,S>,Choice2<C,B>>
cocartesian()
Choose some typeC
or this profunctor's carrier types.<Z> Tagged<Z,B>
contraMap(Fn1<? super Z,? extends S> fn)
Contravariantly mapA <- B
.<Z,C>
Tagged<Z,C>diMap(Fn1<? super Z,? extends S> lFn, Fn1<? super B,? extends C> rFn)
Dually map contravariantly over the left parameter and covariantly over the right parameter.<Z> Tagged<Z,B>
diMapL(Fn1<? super Z,? extends S> fn)
Contravariantly map over the left parameter.<C> Tagged<S,C>
diMapR(Fn1<? super B,? extends C> fn)
Covariantly map over the right parameter.<C> Tagged<S,C>
discardL(Applicative<C,Tagged<S,?>> appB)
Sequence both thisApplicative
andappB
, discarding thisApplicative's
result and returningappB
.<C> Tagged<S,B>
discardR(Applicative<C,Tagged<S,?>> appB)
Sequence both thisApplicative
andappB
, discardingappB's
result and returning thisApplicative
.boolean
equals(java.lang.Object other)
<C> Tagged<S,C>
flatMap(Fn1<? super B,? extends Monad<C,Tagged<S,?>>> f)
Chain dependent computations that may continue or short-circuit based on previous results.<C> Tagged<S,C>
fmap(Fn1<? super B,? extends C> fn)
Covariantly transmute this functor's parameter using the given mapping function.int
hashCode()
<C> Tagged<S,C>
pure(C c)
Lift the valueb
into this applicative functor.static <S> Pure<Tagged<S,?>>
pureTagged()
java.lang.String
toString()
<C> Tagged<S,C>
trampolineM(Fn1<? super B,? extends MonadRec<RecursiveResult<B,C>,Tagged<S,?>>> fn)
Given some operation yielding aRecursiveResult
inside thisMonadRec
, internally trampoline the operation until it yields atermination
instruction.<C,App extends Applicative<?,App>,TravC extends Traversable<C,Tagged<S,?>>,AppTrav extends Applicative<TravC,App>>
AppTravtraverse(Fn1<? super B,? extends Applicative<C,App>> fn, Fn1<? super TravC,? extends AppTrav> pure)
Applyfn
to each element of this traversable from left to right, and collapse the results into a single resulting applicative, potentially with the assistance of the applicative's pure function.B
unTagged()
Extract the contained value.<C> Tagged<S,C>
zip(Applicative<Fn1<? super B,? extends C>,Tagged<S,?>> appFn)
Given another instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.jnape.palatable.lambda.functor.Cocartesian
choose
-
-
-
-
Field Detail
-
b
private final B b
-
-
Constructor Detail
-
Tagged
public Tagged(B b)
-
-
Method Detail
-
unTagged
public B unTagged()
Extract the contained value.- Returns:
- the value
-
flatMap
public <C> Tagged<S,C> flatMap(Fn1<? super B,? extends Monad<C,Tagged<S,?>>> f)
Chain dependent computations that may continue or short-circuit based on previous results.
-
trampolineM
public <C> Tagged<S,C> trampolineM(Fn1<? super B,? extends MonadRec<RecursiveResult<B,C>,Tagged<S,?>>> fn)
Given some operation yielding aRecursiveResult
inside thisMonadRec
, internally trampoline the operation until it yields atermination
instruction.Stack-safety depends on implementations guaranteeing that the growth of the call stack is a constant factor independent of the number of invocations of the operation. For various examples of how this can be achieved in stereotypical circumstances, see the referenced types.
- Specified by:
trampolineM
in interfaceMonadRec<S,B>
- Type Parameters:
C
- the ultimate resulting carrier type- Parameters:
fn
- the function to internally trampoline- Returns:
- the trampolined
MonadRec
- See Also:
for a basic implementation
,for a implementation
,for an implementation leveraging an already stack-safe
,for a implementation
-
fmap
public <C> Tagged<S,C> fmap(Fn1<? super B,? extends C> fn)
Covariantly transmute this functor's parameter using the given mapping function. Generally this method is specialized to return an instance of the class implementing Functor.- Specified by:
fmap
in interfaceApplicative<S,B>
- Specified by:
fmap
in interfaceFunctor<S,B>
- Specified by:
fmap
in interfaceMonad<S,B>
- Specified by:
fmap
in interfaceMonadRec<S,B>
- Specified by:
fmap
in interfaceTraversable<S,B>
- Type Parameters:
C
- the new parameter type- Parameters:
fn
- the mapping function- Returns:
- a functor over B (the new parameter type)
-
zip
public <C> Tagged<S,C> zip(Applicative<Fn1<? super B,? extends C>,Tagged<S,?>> appFn)
Given another instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.
-
discardL
public <C> Tagged<S,C> discardL(Applicative<C,Tagged<S,?>> appB)
Sequence both thisApplicative
andappB
, discarding thisApplicative's
result and returningappB
. This is generally useful for sequentially performing side-effects.
-
discardR
public <C> Tagged<S,B> discardR(Applicative<C,Tagged<S,?>> appB)
Sequence both thisApplicative
andappB
, discardingappB's
result and returning thisApplicative
. This is generally useful for sequentially performing side-effects.
-
traverse
public <C,App extends Applicative<?,App>,TravC extends Traversable<C,Tagged<S,?>>,AppTrav extends Applicative<TravC,App>> AppTrav traverse(Fn1<? super B,? extends Applicative<C,App>> fn, Fn1<? super TravC,? extends AppTrav> pure)
Applyfn
to each element of this traversable from left to right, and collapse the results into a single resulting applicative, potentially with the assistance of the applicative's pure function.- Specified by:
traverse
in interfaceTraversable<S,B>
- Type Parameters:
C
- the resulting element typeApp
- the result applicative typeTravC
- this Traversable instance over BAppTrav
- the full inferred resulting type from the traversal- Parameters:
fn
- the function to applypure
- the applicative pure function- Returns:
- the traversed Traversable, wrapped inside an applicative
-
cocartesian
public <C> Tagged<Choice2<C,S>,Choice2<C,B>> cocartesian()
Choose some typeC
or this profunctor's carrier types.- Specified by:
cocartesian
in interfaceCocartesian<S,B,Tagged<?,?>>
- Type Parameters:
C
- the choice type- Returns:
- the cocartesian-costrengthened profunctor
-
diMap
public <Z,C> Tagged<Z,C> diMap(Fn1<? super Z,? extends S> lFn, Fn1<? super B,? extends C> rFn)
Dually map contravariantly over the left parameter and covariantly over the right parameter. This is isomorphic todiMapL(lFn).diMapR(rFn)
.- Specified by:
diMap
in interfaceCocartesian<S,B,Tagged<?,?>>
- Specified by:
diMap
in interfaceProfunctor<S,B,Tagged<?,?>>
- Type Parameters:
Z
- the new left parameter typeC
- the new right parameter type- Parameters:
lFn
- the left parameter mapping functionrFn
- the right parameter mapping function- Returns:
- a profunctor over Z (the new left parameter type) and C (the new right parameter type)
-
diMapL
public <Z> Tagged<Z,B> diMapL(Fn1<? super Z,? extends S> fn)
Contravariantly map over the left parameter.- Specified by:
diMapL
in interfaceCocartesian<S,B,Tagged<?,?>>
- Specified by:
diMapL
in interfaceProfunctor<S,B,Tagged<?,?>>
- Type Parameters:
Z
- the new left parameter type- Parameters:
fn
- the mapping function- Returns:
- a profunctor over Z (the new left parameter type) and C (the same right parameter type)
-
diMapR
public <C> Tagged<S,C> diMapR(Fn1<? super B,? extends C> fn)
Covariantly map over the right parameter. For all profunctors that are also functors, it should hold thatdiMapR(f) == fmap(f)
.- Specified by:
diMapR
in interfaceCocartesian<S,B,Tagged<?,?>>
- Specified by:
diMapR
in interfaceProfunctor<S,B,Tagged<?,?>>
- Type Parameters:
C
- the new right parameter type- Parameters:
fn
- the mapping function- Returns:
- a profunctor over A (the same left parameter type) and C (the new right parameter type)
-
contraMap
public <Z> Tagged<Z,B> contraMap(Fn1<? super Z,? extends S> fn)
Contravariantly mapA <- B
.- Specified by:
contraMap
in interfaceCocartesian<S,B,Tagged<?,?>>
- Specified by:
contraMap
in interfaceContravariant<S,B>
- Specified by:
contraMap
in interfaceProfunctor<S,B,Tagged<?,?>>
- Type Parameters:
Z
- the new parameter type- Parameters:
fn
- the mapping function- Returns:
- the mapped Contravariant functor instance
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-