Class Tuple2<_1,_2>
java.lang.Object
com.jnape.palatable.lambda.adt.hlist.HList
com.jnape.palatable.lambda.adt.hlist.HList.HCons<_1,SingletonHList<_2>>
com.jnape.palatable.lambda.adt.hlist.Tuple2<_1,_2>
- Type Parameters:
_1- The first slot element type_2- The second slot element type
- All Implemented Interfaces:
Product2<_1,,_2> Applicative<_2,,Tuple2<_1, ?>> Bifunctor<_1,,_2, Tuple2<?, ?>> BoundedBifunctor<_1,,_2, Object, Object, Tuple2<?, ?>> Functor<_2,,Tuple2<_1, ?>> Monad<_2,,Tuple2<_1, ?>> MonadRec<_2,,Tuple2<_1, ?>> MonadWriter<_1,,_2, Tuple2<_1, ?>> Traversable<_2,,Tuple2<_1, ?>> Map.Entry<_1,_2>
public class Tuple2<_1,_2>
extends HList.HCons<_1,SingletonHList<_2>>
implements Product2<_1,_2>, MonadRec<_2,Tuple2<_1,?>>, MonadWriter<_1,_2,Tuple2<_1,?>>, Bifunctor<_1,_2,Tuple2<?,?>>, Traversable<_2,Tuple2<_1,?>>
A 2-element tuple product type, implemented as a specialized HList. Supports random access.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.jnape.palatable.lambda.adt.hlist.HList
HList.HCons<Head,Tail extends HList>, HList.HNil -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription_1()Retrieve the first element._2()Retrieve the second element.<_1Prime,_2Prime>
Tuple2<_1Prime, _2Prime> Dually map covariantly over both the left and right parameters.Covariantly map over the left parameter.Covariantly map over the right parameter.Update the accumulated state.cons(_0 _0) Cons an element onto the front of this HList.discardL(Applicative<_2Prime, Tuple2<_1, ?>> appB) Sequence both thisApplicativeandappB, discarding thisApplicative'sresult and returningappB.discardR(Applicative<_2Prime, Tuple2<_1, ?>> appB) Sequence both thisApplicativeandappB, discardingappB'sresult and returning thisApplicative.static <A> Tuple2<A, A> fill(A a) Given a value of typeA, produce an instance of this tuple with each slot set to that value.Chain dependent computations that may continue or short-circuit based on previous results.Covariantly transmute this functor's parameter using the given mapping function.static <K,V> Tuple2 <K, V> Static factory method for creatingTuple2s fromMap.Entrys.fromIterable(Iterable<A> as) getKey()getValue()init()Returns aof the first element.SingletonHList<_1>invert()Rotate the first two slots of this product.Given alazyinstance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.Map the accumulation into a value and pair it with the current output.pure(_2Prime _2Prime) Lift the valuebinto this applicative functor.pureTuple(_1 _1) snoc(_3 _3) Snoc an element onto the back of thisTuple2.trampolineM(Fn1<? super _2, ? extends MonadRec<RecursiveResult<_2, _2Prime>, Tuple2<_1, ?>>> fn) Given some operation yielding aRecursiveResultinside thisMonadRec, internally trampoline the operation until it yields aterminationinstruction.<_2Prime,App extends Applicative<?, App>, TravB extends Traversable<_2Prime, Tuple2<_1, ?>>, AppTrav extends Applicative<TravB, App>>
AppTravtraverse(Fn1<? super _2, ? extends Applicative<_2Prime, 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 com.jnape.palatable.lambda.adt.hlist.HList.HCons
equals, hashCode, head, tailMethods inherited from class com.jnape.palatable.lambda.adt.hlist.HList
cons, nil, singletonHList, toString, tuple, tuple, tuple, tuple, tuple, tuple, tuple
-
Field Details
-
_1
-
_2
-
-
Constructor Details
-
Tuple2
Tuple2(_1 _1, SingletonHList<_2> tail)
-
-
Method Details
-
listens
Map the accumulation into a value and pair it with the current output.- Specified by:
listensin interfaceMonadWriter<_1,_2, Tuple2<_1, ?>> - Type Parameters:
_3- the mapped output- Parameters:
fn- the mapping function- Returns:
- the updated
MonadWriter
-
censor
Update the accumulated state.- Specified by:
censorin interfaceMonadWriter<_1,_2, Tuple2<_1, ?>> - Parameters:
fn- the update function- Returns:
- the updated
MonadWriter
-
cons
Cons an element onto the front of this HList.- Overrides:
consin classHList.HCons<_1,SingletonHList<_2>> - Type Parameters:
_0- the new head type- Parameters:
_0- the new head element- Returns:
- the updated HList
-
snoc
Snoc an element onto the back of thisTuple2.- Type Parameters:
_3- the new last element type- Parameters:
_3- the new last element- Returns:
- the new
Tuple3
-
_1
Retrieve the first element. -
_2
Retrieve the second element. -
getKey
-
getValue
-
setValue
-
invert
Rotate the first two slots of this product. -
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<_1,_2> - Specified by:
fmapin interfaceFunctor<_1,_2> - Specified by:
fmapin interfaceMonad<_1,_2> - Specified by:
fmapin interfaceMonadRec<_1,_2> - Specified by:
fmapin interfaceMonadWriter<_1,_2, Tuple2<_1, ?>> - Specified by:
fmapin interfaceTraversable<_1,_2> - Type Parameters:
_2Prime- 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<_1,_2, Tuple2<?, ?>> - Specified by:
biMapLin interfaceBoundedBifunctor<_1,_2, Object, Object, Tuple2<?, ?>> - Type Parameters:
_1Prime- 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<_1,_2, Tuple2<?, ?>> - Specified by:
biMapRin interfaceBoundedBifunctor<_1,_2, Object, Object, Tuple2<?, ?>> - Type Parameters:
_2Prime- 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 <_1Prime,_2Prime> Tuple2<_1Prime,_2Prime> biMap(Fn1<? super _1, ? extends _1Prime> lFn, Fn1<? super _2, ? extends _2Prime> rFn) Dually map covariantly over both the left and right parameters. This is isomorphic tobiMapL(lFn).biMapR(rFn).- Specified by:
biMapin interfaceBifunctor<_1,_2, Tuple2<?, ?>> - Specified by:
biMapin interfaceBoundedBifunctor<_1,_2, Object, Object, Tuple2<?, ?>> - Type Parameters:
_1Prime- the new left parameter type_2Prime- 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.- Specified by:
purein interfaceApplicative<_1,_2> - Specified by:
purein interfaceMonad<_1,_2> - Specified by:
purein interfaceMonadRec<_1,_2> - Specified by:
purein interfaceMonadWriter<_1,_2, Tuple2<_1, ?>> - Type Parameters:
_2Prime- the type of the returned applicative's parameter- Parameters:
_2Prime- the value- Returns:
- an instance of this applicative over b
-
zip
public <_2Prime> Tuple2<_1,_2Prime> zip(Applicative<Fn1<? super _2, ? extends _2Prime>, Tuple2<_1, ?>> appFn) Given another instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.- Specified by:
zipin interfaceApplicative<_1,_2> - Specified by:
zipin interfaceMonad<_1,_2> - Specified by:
zipin interfaceMonadRec<_1,_2> - Specified by:
zipin interfaceMonadWriter<_1,_2, Tuple2<_1, ?>> - Type Parameters:
_2Prime- the resulting applicative parameter type- Parameters:
appFn- the other applicative instance- Returns:
- the mapped applicative
-
lazyZip
public <_2Prime> Lazy<Tuple2<_1,_2Prime>> lazyZip(Lazy<? extends Applicative<Fn1<? super _2, ? extends _2Prime>, Tuple2<_1, ?>>> 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<_1,_2> - Specified by:
lazyZipin interfaceMonad<_1,_2> - Specified by:
lazyZipin interfaceMonadRec<_1,_2> - Specified by:
lazyZipin interfaceMonadWriter<_1,_2, Tuple2<_1, ?>> - Type Parameters:
_2Prime- 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.- Specified by:
discardLin interfaceApplicative<_1,_2> - Specified by:
discardLin interfaceMonad<_1,_2> - Specified by:
discardLin interfaceMonadRec<_1,_2> - Specified by:
discardLin interfaceMonadWriter<_1,_2, Tuple2<_1, ?>> - Type Parameters:
_2Prime- the type of the returned Applicative's parameter- Parameters:
appB- the other Applicative- Returns:
- appB
-
discardR
Sequence both thisApplicativeandappB, discardingappB'sresult and returning thisApplicative. This is generally useful for sequentially performing side-effects.- Specified by:
discardRin interfaceApplicative<_1,_2> - Specified by:
discardRin interfaceMonad<_1,_2> - Specified by:
discardRin interfaceMonadRec<_1,_2> - Specified by:
discardRin interfaceMonadWriter<_1,_2, Tuple2<_1, ?>> - Type Parameters:
_2Prime- the type of appB's parameter- Parameters:
appB- the other Applicative- Returns:
- this Applicative
-
flatMap
public <_2Prime> Tuple2<_1,_2Prime> flatMap(Fn1<? super _2, ? extends Monad<_2Prime, Tuple2<_1, ?>>> f) Chain dependent computations that may continue or short-circuit based on previous results.- Specified by:
flatMapin interfaceMonad<_1,_2> - Specified by:
flatMapin interfaceMonadRec<_1,_2> - Specified by:
flatMapin interfaceMonadWriter<_1,_2, Tuple2<_1, ?>> - Type Parameters:
_2Prime- the resulting monad parameter type- Parameters:
f- the dependent computation over A- Returns:
- the new monad instance
-
trampolineM
public <_2Prime> Tuple2<_1,_2Prime> trampolineM(Fn1<? super _2, ? extends MonadRec<RecursiveResult<_2, _2Prime>, Tuple2<_1, ?>>> 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<_1,_2> - Type Parameters:
_2Prime- the ultimate resulting carrier type- Parameters:
fn- the function to internally trampoline- Returns:
- the trampolined
MonadRec - See Also:
-
traverse
public <_2Prime,App extends Applicative<?, AppTrav traverseApp>, TravB extends Traversable<_2Prime, Tuple2<_1, ?>>, AppTrav extends Applicative<TravB, App>> (Fn1<? super _2, ? extends Applicative<_2Prime, 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<_1,_2> - Type Parameters:
_2Prime- 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
-
init
Returns aof the first element.SingletonHList<_1>- Returns:
- The
SingletonHList<_1>
-
fromEntry
Static factory method for creatingTuple2s fromMap.Entrys.- Type Parameters:
K- the key parameter type, and first (head) element typeV- the value parameter type, and second element type- Parameters:
entry- the map entry- Returns:
- the newly created Tuple2
-
fill
Given a value of typeA, produce an instance of this tuple with each slot set to that value.- Type Parameters:
A- the value type- Parameters:
a- the value to fill the tuple with- Returns:
- the filled tuple
-
fromIterable
-
pureTuple
- Type Parameters:
_1- the head element type- Parameters:
_1- the head element- Returns:
- the
Pureinstance
-