Class Choice5<A,B,C,D,E>
- java.lang.Object
-
- com.jnape.palatable.lambda.adt.choice.Choice5<A,B,C,D,E>
-
- Type Parameters:
A
- the first possible typeB
- the second possible typeC
- the third possible typeD
- the fourth possible typeE
- the fifth possible type
- All Implemented Interfaces:
CoProduct5<A,B,C,D,E,Choice5<A,B,C,D,E>>
,Applicative<E,Choice5<A,B,C,D,?>>
,Bifunctor<D,E,Choice5<A,B,C,?,?>>
,BoundedBifunctor<D,E,java.lang.Object,java.lang.Object,Choice5<A,B,C,?,?>>
,Functor<E,Choice5<A,B,C,D,?>>
,Monad<E,Choice5<A,B,C,D,?>>
,MonadRec<E,Choice5<A,B,C,D,?>>
,Traversable<E,Choice5<A,B,C,D,?>>
- Direct Known Subclasses:
Choice5._A
,Choice5._B
,Choice5._C
,Choice5._D
,Choice5._E
public abstract class Choice5<A,B,C,D,E> extends java.lang.Object implements CoProduct5<A,B,C,D,E,Choice5<A,B,C,D,E>>, MonadRec<E,Choice5<A,B,C,D,?>>, Bifunctor<D,E,Choice5<A,B,C,?,?>>, Traversable<E,Choice5<A,B,C,D,?>>
Canonical ADT representation ofCoProduct5
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
Choice5._A<A,B,C,D,E>
private static class
Choice5._B<A,B,C,D,E>
private static class
Choice5._C<A,B,C,D,E>
private static class
Choice5._D<A,B,C,D,E>
private static class
Choice5._E<A,B,C,D,E>
-
Constructor Summary
Constructors Modifier Constructor Description private
Choice5()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <A,B,C,D,E>
Choice5<A,B,C,D,E>a(A a)
Static factory method for wrapping a value of typeA
in aChoice5
.static <A,B,C,D,E>
Choice5<A,B,C,D,E>b(B b)
Static factory method for wrapping a value of typeB
in aChoice5
.<F,G>
Choice5<A,B,C,F,G>biMap(Fn1<? super D,? extends F> lFn, Fn1<? super E,? extends G> rFn)
Dually map covariantly over both the left and right parameters.<F> Choice5<A,B,C,F,E>
biMapL(Fn1<? super D,? extends F> fn)
Covariantly map over the left parameter.<F> Choice5<A,B,C,D,F>
biMapR(Fn1<? super E,? extends F> fn)
Covariantly map over the right parameter.static <A,B,C,D,E>
Choice5<A,B,C,D,E>c(C c)
Static factory method for wrapping a value of typeC
in aChoice5
.Choice4<A,B,C,D>
converge(Fn1<? super E,? extends CoProduct4<A,B,C,D,?>> convergenceFn)
Converge this coproduct down to a lower order coproduct by mapping the last possible type into an earlier possible type.static <A,B,C,D,E>
Choice5<A,B,C,D,E>d(D d)
Static factory method for wrapping a value of typeD
in aChoice5
.<F> Choice5<A,B,C,D,F>
discardL(Applicative<F,Choice5<A,B,C,D,?>> appB)
Sequence both thisApplicative
andappB
, discarding thisApplicative's
result and returningappB
.<F> Choice5<A,B,C,D,E>
discardR(Applicative<F,Choice5<A,B,C,D,?>> appB)
Sequence both thisApplicative
andappB
, discardingappB's
result and returning thisApplicative
.<F> Choice6<A,B,C,D,E,F>
diverge()
Diverge this coproduct by introducing another possible type that it could represent.static <A,B,C,D,E>
Choice5<A,B,C,D,E>e(E e)
Static factory method for wrapping a value of typeE
in aChoice5
.<F> Choice5<A,B,C,D,F>
flatMap(Fn1<? super E,? extends Monad<F,Choice5<A,B,C,D,?>>> f)
Chain dependent computations that may continue or short-circuit based on previous results.<F> Choice5<A,B,C,D,F>
fmap(Fn1<? super E,? extends F> fn)
Covariantly transmute this functor's parameter using the given mapping function.<F> Lazy<Choice5<A,B,C,D,F>>
lazyZip(Lazy<? extends Applicative<Fn1<? super E,? extends F>,Choice5<A,B,C,D,?>>> lazyAppFn)
Given alazy
instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.Tuple5<Maybe<A>,Maybe<B>,Maybe<C>,Maybe<D>,Maybe<E>>
project()
Specialize this choice's projection to aTuple5
.<F> Choice5<A,B,C,D,F>
pure(F f)
Lift the valueb
into this applicative functor.static <A,B,C,D>
Pure<Choice5<A,B,C,D,?>>pureChoice()
<F> Choice5<A,B,C,D,F>
trampolineM(Fn1<? super E,? extends MonadRec<RecursiveResult<E,F>,Choice5<A,B,C,D,?>>> fn)
Given some operation yielding aRecursiveResult
inside thisMonadRec
, internally trampoline the operation until it yields atermination
instruction.<F,App extends Applicative<?,App>,TravB extends Traversable<F,Choice5<A,B,C,D,?>>,AppTrav extends Applicative<TravB,App>>
AppTravtraverse(Fn1<? super E,? extends Applicative<F,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.<F> Choice5<A,B,C,D,F>
zip(Applicative<Fn1<? super E,? extends F>,Choice5<A,B,C,D,?>> 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, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Method Detail
-
project
public Tuple5<Maybe<A>,Maybe<B>,Maybe<C>,Maybe<D>,Maybe<E>> project()
Specialize this choice's projection to aTuple5
.
-
diverge
public <F> Choice6<A,B,C,D,E,F> diverge()
Diverge this coproduct by introducing another possible type that it could represent.
-
converge
public Choice4<A,B,C,D> converge(Fn1<? super E,? extends CoProduct4<A,B,C,D,?>> convergenceFn)
Converge this coproduct down to a lower order coproduct by mapping the last possible type into an earlier possible type.- Specified by:
converge
in interfaceCoProduct5<A,B,C,D,E,Choice5<A,B,C,D,E>>
- Parameters:
convergenceFn
- morphismE ->
CoProduct4
<A, B, C, D>- Returns:
- a
CoProduct4
<A, B, C, D>
-
fmap
public <F> Choice5<A,B,C,D,F> fmap(Fn1<? super E,? extends F> 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<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:
F
- the new parameter type- Parameters:
fn
- the mapping function- Returns:
- a functor over B (the new parameter type)
-
biMapL
public <F> Choice5<A,B,C,F,E> biMapL(Fn1<? super D,? extends F> fn)
Covariantly map over the left parameter.
-
biMapR
public <F> Choice5<A,B,C,D,F> biMapR(Fn1<? super E,? extends F> fn)
Covariantly map over the right parameter. For all bifunctors that are also functors, it should hold thatbiMapR(f) == fmap(f)
.
-
biMap
public <F,G> Choice5<A,B,C,F,G> biMap(Fn1<? super D,? extends F> lFn, Fn1<? super E,? extends G> 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<A,B,C,D,E>
- Type Parameters:
F
- the new left parameter typeG
- 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)
-
zip
public <F> Choice5<A,B,C,D,F> zip(Applicative<Fn1<? super E,? extends F>,Choice5<A,B,C,D,?>> appFn)
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 <F> Lazy<Choice5<A,B,C,D,F>> lazyZip(Lazy<? extends Applicative<Fn1<? super E,? extends F>,Choice5<A,B,C,D,?>>> 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:
F
- the resulting applicative parameter type- Parameters:
lazyAppFn
- the lazy other applicative instance- Returns:
- the mapped applicative
- See Also:
Maybe
,Either
-
discardL
public <F> Choice5<A,B,C,D,F> discardL(Applicative<F,Choice5<A,B,C,D,?>> appB)
Sequence both thisApplicative
andappB
, discarding thisApplicative's
result and returningappB
. This is generally useful for sequentially performing side-effects.
-
discardR
public <F> Choice5<A,B,C,D,E> discardR(Applicative<F,Choice5<A,B,C,D,?>> appB)
Sequence both thisApplicative
andappB
, discardingappB's
result and returning thisApplicative
. This is generally useful for sequentially performing side-effects.
-
flatMap
public <F> Choice5<A,B,C,D,F> flatMap(Fn1<? super E,? extends Monad<F,Choice5<A,B,C,D,?>>> f)
Chain dependent computations that may continue or short-circuit based on previous results.
-
trampolineM
public <F> Choice5<A,B,C,D,F> trampolineM(Fn1<? super E,? extends MonadRec<RecursiveResult<E,F>,Choice5<A,B,C,D,?>>> 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:
F
- 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
-
traverse
public <F,App extends Applicative<?,App>,TravB extends Traversable<F,Choice5<A,B,C,D,?>>,AppTrav extends Applicative<TravB,App>> AppTrav traverse(Fn1<? super E,? extends Applicative<F,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:
F
- 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
public static <A,B,C,D,E> Choice5<A,B,C,D,E> a(A a)
Static factory method for wrapping a value of typeA
in aChoice5
.- Type Parameters:
A
- the first possible typeB
- the second possible typeC
- the third possible typeD
- the fourth possible typeE
- the fifth possible type- Parameters:
a
- the value- Returns:
- the wrapped value as a
Choice5
<A, B, C, D, E>
-
b
public static <A,B,C,D,E> Choice5<A,B,C,D,E> b(B b)
Static factory method for wrapping a value of typeB
in aChoice5
.- Type Parameters:
A
- the first possible typeB
- the second possible typeC
- the third possible typeD
- the fourth possible typeE
- the fifth possible type- Parameters:
b
- the value- Returns:
- the wrapped value as a
Choice5
<A, B, C, D, E>
-
c
public static <A,B,C,D,E> Choice5<A,B,C,D,E> c(C c)
Static factory method for wrapping a value of typeC
in aChoice5
.- Type Parameters:
A
- the first possible typeB
- the second possible typeC
- the third possible typeD
- the fourth possible typeE
- the fifth possible type- Parameters:
c
- the value- Returns:
- the wrapped value as a
Choice5
<A, B, C, D, E>
-
d
public static <A,B,C,D,E> Choice5<A,B,C,D,E> d(D d)
Static factory method for wrapping a value of typeD
in aChoice5
.- Type Parameters:
A
- the first possible typeB
- the second possible typeC
- the third possible typeD
- the fourth possible typeE
- the fifth possible type- Parameters:
d
- the value- Returns:
- the wrapped value as a
Choice5
<A, B, C, D, E>
-
e
public static <A,B,C,D,E> Choice5<A,B,C,D,E> e(E e)
Static factory method for wrapping a value of typeE
in aChoice5
.- Type Parameters:
A
- the first possible typeB
- the second possible typeC
- the third possible typeD
- the fourth possible typeE
- the fifth possible type- Parameters:
e
- the value- Returns:
- the wrapped value as a
Choice5
<A, B, C, D, E>
-
-