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,java.lang.Object,java.lang.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 java.lang.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 ofCoProduct3
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
Choice3._A<A,B,C>
private static class
Choice3._B<A,B,C>
private static class
Choice3._C<A,B,C>
-
Constructor Summary
Constructors Modifier Constructor Description private
Choice3()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <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
.<D,E>
Choice3<A,D,E>biMap(Fn1<? super B,? extends D> lFn, Fn1<? super C,? extends E> rFn)
Dually map covariantly over both the left and right parameters.<D> Choice3<A,D,C>
biMapL(Fn1<? super B,? extends D> fn)
Covariantly map over the left parameter.<D> Choice3<A,B,D>
biMapR(Fn1<? super C,? extends D> fn)
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
.Choice2<A,B>
converge(Fn1<? super C,? extends CoProduct2<A,B,?>> convergenceFn)
Converge this coproduct down to a lower order coproduct by mapping the last possible type into an earlier possible type.<D> Choice3<A,B,D>
discardL(Applicative<D,Choice3<A,B,?>> appB)
Sequence both thisApplicative
andappB
, discarding thisApplicative's
result and returningappB
.<D> Choice3<A,B,C>
discardR(Applicative<D,Choice3<A,B,?>> appB)
Sequence both thisApplicative
andappB
, discardingappB's
result and returning thisApplicative
.<D> Choice4<A,B,C,D>
diverge()
Diverge this coproduct by introducing another possible type that it could represent.<D> Choice3<A,B,D>
flatMap(Fn1<? super C,? extends Monad<D,Choice3<A,B,?>>> f)
Chain dependent computations that may continue or short-circuit based on previous results.<D> Choice3<A,B,D>
fmap(Fn1<? super C,? extends D> fn)
Covariantly transmute this functor's parameter using the given mapping function.<D> Lazy<Choice3<A,B,D>>
lazyZip(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.Tuple3<Maybe<A>,Maybe<B>,Maybe<C>>
project()
Specialize this choice's projection to aTuple3
.<D> Choice3<A,B,D>
pure(D d)
Lift the valueb
into this applicative functor.static <A,B>
Pure<Choice3<A,B,?>>pureChoice()
<D> Choice3<A,B,D>
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.<D> Choice3<A,B,D>
zip(Applicative<Fn1<? super C,? extends D>,Choice3<A,B,?>> 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 Tuple3<Maybe<A>,Maybe<B>,Maybe<C>> project()
Specialize this choice's projection to aTuple3
.
-
diverge
public final <D> Choice4<A,B,C,D> 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:
CoProduct2.diverge()
-
converge
public final Choice2<A,B> converge(Fn1<? super C,? extends CoProduct2<A,B,?>> convergenceFn)
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
public final <D> Choice3<A,B,D> fmap(Fn1<? super C,? extends D> 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:
D
- the new parameter type- Parameters:
fn
- the mapping function- Returns:
- a functor over B (the new parameter type)
-
biMapL
public final <D> Choice3<A,D,C> biMapL(Fn1<? super B,? extends D> fn)
Covariantly map over the left parameter.- Specified by:
biMapL
in interfaceBifunctor<A,B,C>
- Specified by:
biMapL
in interfaceBoundedBifunctor<B,C,java.lang.Object,java.lang.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
public final <D> Choice3<A,B,D> biMapR(Fn1<? super C,? extends D> 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<B,C,java.lang.Object,java.lang.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,E> biMap(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,java.lang.Object,java.lang.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)
-
zip
public <D> Choice3<A,B,D> zip(Applicative<Fn1<? super C,? extends D>,Choice3<A,B,?>> 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 <D> Lazy<Choice3<A,B,D>> lazyZip(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:
Maybe
,Either
-
discardL
public <D> Choice3<A,B,D> discardL(Applicative<D,Choice3<A,B,?>> appB)
Sequence both thisApplicative
andappB
, discarding thisApplicative's
result and returningappB
. This is generally useful for sequentially performing side-effects.
-
discardR
public <D> Choice3<A,B,C> discardR(Applicative<D,Choice3<A,B,?>> appB)
Sequence both thisApplicative
andappB
, discardingappB's
result and returning thisApplicative
. This is generally useful for sequentially performing side-effects.
-
flatMap
public <D> Choice3<A,B,D> flatMap(Fn1<? super C,? extends Monad<D,Choice3<A,B,?>>> f)
Chain dependent computations that may continue or short-circuit based on previous results.
-
trampolineM
public <D> Choice3<A,B,D> 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.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:
for a basic implementation
,for a implementation
,for an implementation leveraging an already stack-safe
,for a implementation
-
traverse
public <D,App extends Applicative<?,App>,TravB extends Traversable<D,Choice3<A,B,?>>,AppTrav extends Applicative<TravB,App>> AppTrav traverse(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
public static <A,B,C> Choice3<A,B,C> a(A 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
public static <A,B,C> Choice3<A,B,C> b(B 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
public static <A,B,C> Choice3<A,B,C> c(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>
-
-