Class SingletonHList<_1>
- java.lang.Object
-
- com.jnape.palatable.lambda.adt.hlist.HList
-
- com.jnape.palatable.lambda.adt.hlist.HList.HCons<_1,HList.HNil>
-
- com.jnape.palatable.lambda.adt.hlist.SingletonHList<_1>
-
- Type Parameters:
_1- The single slot element type
- All Implemented Interfaces:
Applicative<_1,SingletonHList<?>>,Functor<_1,SingletonHList<?>>,Monad<_1,SingletonHList<?>>,MonadRec<_1,SingletonHList<?>>,Traversable<_1,SingletonHList<?>>
public class SingletonHList<_1> extends HList.HCons<_1,HList.HNil> implements MonadRec<_1,SingletonHList<?>>, Traversable<_1,SingletonHList<?>>
A singleton HList. Supports random access.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.jnape.palatable.lambda.adt.hlist.HList
HList.HCons<Head,Tail extends HList>, HList.HNil
-
-
Constructor Summary
Constructors Constructor Description SingletonHList(_1 _1)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <_0> Tuple2<_0,_1>cons(_0 _0)Cons an element onto the front of this HList.<_1Prime> SingletonHList<_1Prime>discardL(Applicative<_1Prime,SingletonHList<?>> appB)Sequence both thisApplicativeandappB, discarding thisApplicative'sresult and returningappB.<_1Prime> SingletonHList<_1>discardR(Applicative<_1Prime,SingletonHList<?>> appB)Sequence both thisApplicativeandappB, discardingappB'sresult and returning thisApplicative.<_1Prime> SingletonHList<_1Prime>flatMap(Fn1<? super _1,? extends Monad<_1Prime,SingletonHList<?>>> f)Chain dependent computations that may continue or short-circuit based on previous results.<_1Prime> SingletonHList<_1Prime>fmap(Fn1<? super _1,? extends _1Prime> fn)Covariantly transmute this functor's parameter using the given mapping function.<R> Rinto(Fn1<? super _1,? extends R> fn)ApplyHList.HCons.head()tofnand return the result.<_1Prime> Lazy<SingletonHList<_1Prime>>lazyZip(Lazy<? extends Applicative<Fn1<? super _1,? extends _1Prime>,SingletonHList<?>>> lazyAppFn)Given alazyinstance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.<_1Prime> SingletonHList<_1Prime>pure(_1Prime _1Prime)Lift the valuebinto this applicative functor.static Pure<SingletonHList<?>>pureSingletonHList()The canonicalPureinstance forSingletonHList.<_2> Tuple2<_1,_2>snoc(_2 _2)Snoc an element onto the back of thisSingletonHList.<_1Prime> SingletonHList<_1Prime>trampolineM(Fn1<? super _1,? extends MonadRec<RecursiveResult<_1,_1Prime>,SingletonHList<?>>> fn)Given some operation yielding aRecursiveResultinside thisMonadRec, internally trampoline the operation until it yields aterminationinstruction.<B,App extends Applicative<?,App>,TravB extends Traversable<B,SingletonHList<?>>,AppTrav extends Applicative<TravB,App>>
AppTravtraverse(Fn1<? super _1,? extends Applicative<B,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.<_1Prime> SingletonHList<_1Prime>zip(Applicative<Fn1<? super _1,? extends _1Prime>,SingletonHList<?>> 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 com.jnape.palatable.lambda.adt.hlist.HList.HCons
equals, hashCode, head, tail
-
Methods inherited from class com.jnape.palatable.lambda.adt.hlist.HList
cons, nil, singletonHList, toString, tuple, tuple, tuple, tuple, tuple, tuple, tuple
-
-
-
-
Constructor Detail
-
SingletonHList
SingletonHList(_1 _1)
-
-
Method Detail
-
cons
public <_0> Tuple2<_0,_1> cons(_0 _0)
Cons an element onto the front of this HList.- Overrides:
consin classHList.HCons<_1,HList.HNil>- Type Parameters:
_0- the new head type- Parameters:
_0- the new head element- Returns:
- the updated HList
-
snoc
public <_2> Tuple2<_1,_2> snoc(_2 _2)
Snoc an element onto the back of thisSingletonHList.- Type Parameters:
_2- the new last element type- Parameters:
_2- the new last element- Returns:
- the new
Tuple2
-
fmap
public <_1Prime> SingletonHList<_1Prime> fmap(Fn1<? super _1,? extends _1Prime> 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:
fmapin interfaceApplicative<_1,SingletonHList<?>>- Specified by:
fmapin interfaceFunctor<_1,SingletonHList<?>>- Specified by:
fmapin interfaceMonad<_1,SingletonHList<?>>- Specified by:
fmapin interfaceMonadRec<_1,SingletonHList<?>>- Specified by:
fmapin interfaceTraversable<_1,SingletonHList<?>>- Type Parameters:
_1Prime- the new parameter type- Parameters:
fn- the mapping function- Returns:
- a functor over B (the new parameter type)
-
pure
public <_1Prime> SingletonHList<_1Prime> pure(_1Prime _1Prime)
Lift the valuebinto this applicative functor.- Specified by:
purein interfaceApplicative<_1,SingletonHList<?>>- Specified by:
purein interfaceMonad<_1,SingletonHList<?>>- Specified by:
purein interfaceMonadRec<_1,SingletonHList<?>>- Type Parameters:
_1Prime- the type of the returned applicative's parameter- Parameters:
_1Prime- the value- Returns:
- an instance of this applicative over b
-
zip
public <_1Prime> SingletonHList<_1Prime> zip(Applicative<Fn1<? super _1,? extends _1Prime>,SingletonHList<?>> 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,SingletonHList<?>>- Specified by:
zipin interfaceMonad<_1,SingletonHList<?>>- Specified by:
zipin interfaceMonadRec<_1,SingletonHList<?>>- Type Parameters:
_1Prime- the resulting applicative parameter type- Parameters:
appFn- the other applicative instance- Returns:
- the mapped applicative
-
lazyZip
public <_1Prime> Lazy<SingletonHList<_1Prime>> lazyZip(Lazy<? extends Applicative<Fn1<? super _1,? extends _1Prime>,SingletonHList<?>>> 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,SingletonHList<?>>- Specified by:
lazyZipin interfaceMonad<_1,SingletonHList<?>>- Specified by:
lazyZipin interfaceMonadRec<_1,SingletonHList<?>>- Type Parameters:
_1Prime- the resulting applicative parameter type- Parameters:
lazyAppFn- the lazy other applicative instance- Returns:
- the mapped applicative
- See Also:
Maybe,Either
-
discardL
public <_1Prime> SingletonHList<_1Prime> discardL(Applicative<_1Prime,SingletonHList<?>> appB)
Sequence both thisApplicativeandappB, discarding thisApplicative'sresult and returningappB. This is generally useful for sequentially performing side-effects.- Specified by:
discardLin interfaceApplicative<_1,SingletonHList<?>>- Specified by:
discardLin interfaceMonad<_1,SingletonHList<?>>- Specified by:
discardLin interfaceMonadRec<_1,SingletonHList<?>>- Type Parameters:
_1Prime- the type of the returned Applicative's parameter- Parameters:
appB- the other Applicative- Returns:
- appB
-
discardR
public <_1Prime> SingletonHList<_1> discardR(Applicative<_1Prime,SingletonHList<?>> appB)
Sequence both thisApplicativeandappB, discardingappB'sresult and returning thisApplicative. This is generally useful for sequentially performing side-effects.- Specified by:
discardRin interfaceApplicative<_1,SingletonHList<?>>- Specified by:
discardRin interfaceMonad<_1,SingletonHList<?>>- Specified by:
discardRin interfaceMonadRec<_1,SingletonHList<?>>- Type Parameters:
_1Prime- the type of appB's parameter- Parameters:
appB- the other Applicative- Returns:
- this Applicative
-
flatMap
public <_1Prime> SingletonHList<_1Prime> flatMap(Fn1<? super _1,? extends Monad<_1Prime,SingletonHList<?>>> f)
Chain dependent computations that may continue or short-circuit based on previous results.- Specified by:
flatMapin interfaceMonad<_1,SingletonHList<?>>- Specified by:
flatMapin interfaceMonadRec<_1,SingletonHList<?>>- Type Parameters:
_1Prime- the resulting monad parameter type- Parameters:
f- the dependent computation over A- Returns:
- the new monad instance
-
trampolineM
public <_1Prime> SingletonHList<_1Prime> trampolineM(Fn1<? super _1,? extends MonadRec<RecursiveResult<_1,_1Prime>,SingletonHList<?>>> 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,SingletonHList<?>>- Type Parameters:
_1Prime- 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 <B,App extends Applicative<?,App>,TravB extends Traversable<B,SingletonHList<?>>,AppTrav extends Applicative<TravB,App>> AppTrav traverse(Fn1<? super _1,? extends Applicative<B,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,SingletonHList<?>>- Type Parameters:
B- 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
-
into
public <R> R into(Fn1<? super _1,? extends R> fn)
ApplyHList.HCons.head()tofnand return the result.- Type Parameters:
R- the return type of the function- Parameters:
fn- the function to apply- Returns:
- the result of applying the head to the function
-
pureSingletonHList
public static Pure<SingletonHList<?>> pureSingletonHList()
The canonicalPureinstance forSingletonHList.- Returns:
- the
Pureinstance
-
-