Class These<A,B>
java.lang.Object
com.jnape.palatable.lambda.adt.These<A,B>
- Type Parameters:
A- the first possible typeB- the second possible type
- All Implemented Interfaces:
CoProduct3<A, B, Tuple2<A,B>, These<A, B>>, Applicative<B, These<A, ?>>, Bifunctor<A, B, These<?, ?>>, BoundedBifunctor<A, B, Object, Object, These<?, ?>>, Functor<B, These<A, ?>>, Monad<B, These<A, ?>>, MonadRec<B, These<A, ?>>, Traversable<B, These<A, ?>>
- Direct Known Subclasses:
These._A, These._B, These.Both
public abstract class These<A,B>
extends Object
implements CoProduct3<A, B, Tuple2<A,B>, These<A,B>>, MonadRec<B, These<A,?>>, Bifunctor<A, B, These<?,?>>, Traversable<B, These<A,?>>
The coproduct of a coproduct (
CoProduct2<A, B>) and its product (Tuple2<A, B>), represented as a CoProduct3<A, B, Tuple2<A,
B>>.-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <A,B> These <A, B> a(A a) Static factory method for wrapping a value of typeAin aThese.static <A,B> These <A, B> b(B b) Static factory method for wrapping a value of typeBin aThese.final <C,D> These <C, D> 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> These <A, B> both(A a, B b) discardL(Applicative<C, These<A, ?>> appB) Sequence both thisApplicativeandappB, discarding thisApplicative'sresult and returningappB.discardR(Applicative<C, These<A, ?>> appB) Sequence both thisApplicativeandappB, discardingappB'sresult and returning thisApplicative.Chain dependent computations that may continue or short-circuit based on previous results.Covariantly transmute this functor's parameter using the given mapping function.fromMaybes(Maybe<A> maybeA, Maybe<B> maybeB) Given alazyinstance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.pure(C c) Lift the valuebinto this applicative functor.trampolineM(Fn1<? super B, ? extends MonadRec<RecursiveResult<B, C>, These<A, ?>>> fn) Given some operation yielding aRecursiveResultinside thisMonadRec, internally trampoline the operation until it yields aterminationinstruction.<C, App extends Applicative<?,App>, TravC extends Traversable<C, These<A, ?>>, AppTrav extends Applicative<TravC, App>>
AppTravtraverse(Fn1<? super B, ? extends Applicative<C, App>> fn, Fn1<? super TravC, ? 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 Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
These
private These()
-
-
Method Details
-
biMap
public final <C,D> These<C,D> biMap(Fn1<? super A, ? extends C> lFn, Fn1<? super B, ? extends D> rFn) Dually map covariantly over both the left and right parameters. This is isomorphic tobiMapL(lFn).biMapR(rFn).- Specified by:
biMapin interfaceBifunctor<A, B, These<?,?>> - Specified by:
biMapin interfaceBoundedBifunctor<A, B, Object, Object, These<?,?>> - Type Parameters:
C- the new left parameter typeD- 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)
-
flatMap
Chain dependent computations that may continue or short-circuit based on previous results. -
trampolineM
public <C> These<A,C> trampolineM(Fn1<? super B, ? extends MonadRec<RecursiveResult<B, C>, These<A, ?>>> 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:
C- the ultimate resulting carrier type- Parameters:
fn- the function to internally trampoline- Returns:
- the trampolined
MonadRec - See Also:
-
pure
Lift the valuebinto this applicative functor. -
traverse
public <C, App extends Applicative<?,App>, TravC extends Traversable<C, These<A, AppTrav traverse?>>, AppTrav extends Applicative<TravC, App>> (Fn1<? super B, ? extends Applicative<C, App>> fn, Fn1<? super TravC, ? 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:
C- the resulting element typeApp- the result applicative typeTravC- 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
-
biMapL
Covariantly map over the left parameter.- Specified by:
biMapLin interfaceBifunctor<A, B, These<?,?>> - Specified by:
biMapLin interfaceBoundedBifunctor<A, B, Object, Object, These<?,?>> - Type Parameters:
Z- 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, These<?,?>> - Specified by:
biMapRin interfaceBoundedBifunctor<A, B, Object, Object, These<?,?>> - Type Parameters:
C- 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)
-
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:
C- the new parameter type- Parameters:
fn- the mapping function- Returns:
- a functor over B (the new parameter type)
-
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 <C> Lazy<These<A,C>> lazyZip(Lazy<? extends Applicative<Fn1<? super B, ? extends C>, These<A, ?>>> 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:
C- 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. -
a
-
b
-
both
- Type Parameters:
A- the first possible typeB- the second possible type- Parameters:
a- the first valueb- the second value- Returns:
- the wrapped values as a
These<A,B>
-
fromMaybes
Convenience method for converting a pair ofMaybes into aMaybeofThese. If bothMaybes areMaybe.just(A)then the result is aMaybe.just(A)both(A, B). If only oneMaybeisMaybe.just(A)then it will beMaybe.just(A)a(A)orMaybe.just(A)b(B). If bothMaybes areMaybe.nothing()then the result will beMaybe.nothing(). -
pureThese
-