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