Class Choice3<A,B,C>
java.lang.Object
com.jnape.palatable.lambda.adt.choice.Choice3<A,B,C>
- Type Parameters:
A
- the first possible typeB
- the second possible typeC
- the third possible type
- All Implemented Interfaces:
CoProduct3<A,
,B, C, Choice3<A, B, C>> Applicative<C,
,Choice3<A, B, ?>> Bifunctor<B,
,C, Choice3<A, ?, ?>> BoundedBifunctor<B,
,C, Object, Object, Choice3<A, ?, ?>> Functor<C,
,Choice3<A, B, ?>> Monad<C,
,Choice3<A, B, ?>> MonadRec<C,
,Choice3<A, B, ?>> Traversable<C,
Choice3<A, B, ?>>
- Direct Known Subclasses:
Choice3._A
,Choice3._B
,Choice3._C
public abstract class Choice3<A,B,C>
extends Object
implements CoProduct3<A,B,C,Choice3<A,B,C>>, MonadRec<C,Choice3<A,B,?>>, Bifunctor<B,C,Choice3<A,?,?>>, Traversable<C,Choice3<A,B,?>>
Canonical ADT representation of
CoProduct3
.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
Choice3._A<A,
B, C> private static final class
Choice3._B<A,
B, C> private static final class
Choice3._C<A,
B, C> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <A,
B, C> Choice3 <A, B, C> a
(A a) Static factory method for wrapping a value of typeA
in aChoice3
.static <A,
B, C> Choice3 <A, B, C> b
(B b) Static factory method for wrapping a value of typeA
in aChoice3
.Dually map covariantly over both the left and right parameters.Covariantly map over the left parameter.Covariantly map over the right parameter.static <A,
B, C> Choice3 <A, B, C> c
(C c) Static factory method for wrapping a value of typeA
in aChoice3
.Converge this coproduct down to a lower order coproduct by mapping the last possible type into an earlier possible type.discardL
(Applicative<D, Choice3<A, B, ?>> appB) Sequence both thisApplicative
andappB
, discarding thisApplicative's
result and returningappB
.discardR
(Applicative<D, Choice3<A, B, ?>> appB) Sequence both thisApplicative
andappB
, discardingappB's
result and returning thisApplicative
.diverge()
Diverge this coproduct by introducing another possible type that it could represent.Chain dependent computations that may continue or short-circuit based on previous results.Covariantly transmute this functor's parameter using the given mapping function.Given alazy
instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.project()
Specialize this choice's projection to aTuple3
.pure
(D d) Lift the valueb
into this applicative functor.trampolineM
(Fn1<? super C, ? extends MonadRec<RecursiveResult<C, D>, Choice3<A, B, ?>>> fn) Given some operation yielding aRecursiveResult
inside thisMonadRec
, internally trampoline the operation until it yields atermination
instruction.<D,
App extends Applicative<?, App>, TravB extends Traversable<D, Choice3<A, B, ?>>, AppTrav extends Applicative<TravB, App>>
AppTravtraverse
(Fn1<? super C, ? extends Applicative<D, App>> fn, Fn1<? super TravB, ? 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.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, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
Choice3
private Choice3()
-
-
Method Details
-
project
Specialize this choice's projection to aTuple3
. -
diverge
Diverge this coproduct by introducing another possible type that it could represent.- Specified by:
diverge
in interfaceCoProduct3<A,
B, C, Choice3<A, B, C>> - Type Parameters:
D
- the additional possible type of this coproduct- Returns:
- a
CoProduct4
<A, B, C, D> - See Also:
-
converge
Converge this coproduct down to a lower order coproduct by mapping the last possible type into an earlier possible type. This is the categorical dual ofCoProduct2.diverge()
, which introduces the typeC
and raises the order from 2 to 3.The following laws hold for any two coproducts of single order difference:
- Cancellation:
coProductN.diverge().converge(CoProductN::a) == coProductN
- Specified by:
converge
in interfaceCoProduct3<A,
B, C, Choice3<A, B, C>> - Parameters:
convergenceFn
- function from last possible type to earlier type- Returns:
- a
CoProduct2
<A, B>
- Cancellation:
-
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<A,
B> - Specified by:
fmap
in interfaceFunctor<A,
B> - Specified by:
fmap
in interfaceMonad<A,
B> - Specified by:
fmap
in interfaceMonadRec<A,
B> - Specified by:
fmap
in interfaceTraversable<A,
B> - Type Parameters:
D
- the new parameter type- Parameters:
fn
- the mapping function- Returns:
- a functor over B (the new parameter type)
-
biMapL
Covariantly map over the left parameter.- Specified by:
biMapL
in interfaceBifunctor<A,
B, C> - Specified by:
biMapL
in interfaceBoundedBifunctor<B,
C, Object, Object, Choice3<A, ?, ?>> - Type Parameters:
D
- the new left parameter type- Parameters:
fn
- the mapping function- Returns:
- a bifunctor over C (the new left parameter) and B (the same right parameter)
-
biMapR
Covariantly map over the right parameter. For all bifunctors that are also functors, it should hold thatbiMapR(f) == fmap(f)
.- Specified by:
biMapR
in interfaceBifunctor<A,
B, C> - Specified by:
biMapR
in interfaceBoundedBifunctor<B,
C, Object, Object, Choice3<A, ?, ?>> - Type Parameters:
D
- the new right parameter type- Parameters:
fn
- the mapping function- Returns:
- a bifunctor over A (the same left parameter) and C (the new right parameter)
-
biMap
public final <D,E> Choice3<A,D, biMapE> (Fn1<? super B, ? extends D> lFn, Fn1<? super C, ? extends E> rFn) Dually map covariantly over both the left and right parameters. This is isomorphic tobiMapL(lFn).biMapR(rFn)
.- Specified by:
biMap
in interfaceBifunctor<A,
B, C> - Specified by:
biMap
in interfaceBoundedBifunctor<B,
C, Object, Object, Choice3<A, ?, ?>> - Type Parameters:
D
- the new left parameter typeE
- the new right parameter type- Parameters:
lFn
- the left parameter mapping functionrFn
- the right parameter mapping function- Returns:
- a bifunctor over C (the new left parameter type) and D (the new right parameter type)
-
pure
Lift the valueb
into this applicative functor. -
zip
Given another instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports. -
lazyZip
public <D> Lazy<Choice3<A,B, lazyZipD>> (Lazy<? extends Applicative<Fn1<? super C, ? extends D>, Choice3<A, B, ?>>> lazyAppFn) Given alazy
instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports. This is useful for applicatives that support lazy evaluation and early termination.- Specified by:
lazyZip
in interfaceApplicative<A,
B> - Specified by:
lazyZip
in interfaceMonad<A,
B> - Specified by:
lazyZip
in interfaceMonadRec<A,
B> - Type Parameters:
D
- the resulting applicative parameter type- Parameters:
lazyAppFn
- the lazy other applicative instance- Returns:
- the mapped applicative
- See Also:
-
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. -
flatMap
Chain dependent computations that may continue or short-circuit based on previous results. -
trampolineM
public <D> Choice3<A,B, trampolineMD> (Fn1<? super C, ? extends MonadRec<RecursiveResult<C, D>, Choice3<A, B, ?>>> 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<A,
B> - Type Parameters:
D
- the ultimate resulting carrier type- Parameters:
fn
- the function to internally trampoline- Returns:
- the trampolined
MonadRec
- See Also:
-
traverse
public <D,App extends Applicative<?, AppTrav traverseApp>, TravB extends Traversable<D, Choice3<A, B, ?>>, AppTrav extends Applicative<TravB, App>> (Fn1<? super C, ? extends Applicative<D, App>> fn, Fn1<? super TravB, ? 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<A,
B> - Type Parameters:
D
- the resulting element typeApp
- the result applicative typeTravB
- 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
-
a
Static factory method for wrapping a value of typeA
in aChoice3
.- Type Parameters:
A
- the first possible typeB
- the second possible typeC
- the third possible type- Parameters:
a
- the value- Returns:
- the wrapped value as a
Choice3
<A, B, C>
-
b
Static factory method for wrapping a value of typeA
in aChoice3
.- Type Parameters:
A
- the first possible typeB
- the second possible typeC
- the third possible type- Parameters:
b
- the value- Returns:
- the wrapped value as a
Choice3
<A, B, C>
-
c
Static factory method for wrapping a value of typeA
in aChoice3
.- Type Parameters:
A
- the first possible typeB
- the second possible typeC
- the third possible type- Parameters:
c
- the value- Returns:
- the wrapped value as a
Choice3
<A, B, C>
-
pureChoice
- Type Parameters:
A
- the first possible typeB
- the second possible type- Returns:
- the
Pure
instance
-