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 classChoice3._A<A,B, C> private static final classChoice3._B<A,B, C> private static final classChoice3._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 typeAin aChoice3.static <A,B, C> Choice3 <A, B, C> b(B b) Static factory method for wrapping a value of typeAin 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 typeAin 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 thisApplicativeandappB, discarding thisApplicative'sresult and returningappB.discardR(Applicative<D, Choice3<A, B, ?>> appB) Sequence both thisApplicativeandappB, discardingappB'sresult 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 alazyinstance 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 valuebinto this applicative functor.trampolineM(Fn1<? super C, ? extends MonadRec<RecursiveResult<C, D>, Choice3<A, B, ?>>> fn) Given some operation yielding aRecursiveResultinside thisMonadRec, internally trampoline the operation until it yields aterminationinstruction.<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) Applyfnto 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:
divergein 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 typeCand 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:
convergein 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:
fmapin interfaceApplicative<A,B> - Specified by:
fmapin interfaceFunctor<A,B> - Specified by:
fmapin interfaceMonad<A,B> - Specified by:
fmapin interfaceMonadRec<A,B> - Specified by:
fmapin 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:
biMapLin interfaceBifunctor<A,B, C> - Specified by:
biMapLin 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:
biMapRin interfaceBifunctor<A,B, C> - Specified by:
biMapRin 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:
biMapin interfaceBifunctor<A,B, C> - Specified by:
biMapin 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 valuebinto 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 alazyinstance 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:
lazyZipin interfaceApplicative<A,B> - Specified by:
lazyZipin interfaceMonad<A,B> - Specified by:
lazyZipin 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 thisApplicativeandappB, discarding thisApplicative'sresult and returningappB. This is generally useful for sequentially performing side-effects. -
discardR
Sequence both thisApplicativeandappB, discardingappB'sresult 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 aRecursiveResultinside thisMonadRec, internally trampoline the operation until it yields aterminationinstruction.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:
trampolineMin 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) Applyfnto 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:
traversein 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 typeAin 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 typeAin 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 typeAin 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
Pureinstance
-