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 Object
implements MonadRec<B,Tagged<S,?>>, Traversable<B,Tagged<S,?>>, Cocartesian<S,B,Tagged<?,?>>
Like
Const
, but the phantom parameter is in the contravariant position, and the value is in covariant
position.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionChoose some typeC
or this profunctor's carrier types.Contravariantly mapA <- B
.<Z,
C> Tagged <Z, C> Dually map contravariantly over the left parameter and covariantly over the right parameter.Contravariantly map over the left parameter.Covariantly map over the right parameter.discardL
(Applicative<C, Tagged<S, ?>> appB) Sequence both thisApplicative
andappB
, discarding thisApplicative's
result and returningappB
.discardR
(Applicative<C, Tagged<S, ?>> appB) Sequence both thisApplicative
andappB
, discardingappB's
result and returning thisApplicative
.boolean
Chain dependent computations that may continue or short-circuit based on previous results.Covariantly transmute this functor's parameter using the given mapping function.int
hashCode()
pure
(C c) Lift the valueb
into this applicative functor.toString()
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.unTagged()
Extract the contained value.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 Details
-
b
-
-
Constructor Details
-
Tagged
-
-
Method Details
-
unTagged
Extract the contained value.- Returns:
- the value
-
flatMap
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:
-
pure
Lift the valueb
into this applicative functor. -
fmap
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
Given another instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports. -
discardL
Sequence both thisApplicative
andappB
, discarding thisApplicative's
result and returningappB
. This is generally useful for sequentially performing side-effects. -
discardR
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<?, AppTrav traverseApp>, TravC extends Traversable<C, Tagged<S, ?>>, AppTrav extends Applicative<TravC, App>> (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
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
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
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
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
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
-
hashCode
public int hashCode() -
toString
-
pureTagged
- Type Parameters:
S
- the phantom type- Returns:
- the
Pure
instance
-