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.
- 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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncons
(_0 _0) Cons an element onto the front of this HList.<_1Prime> SingletonHList
<_1Prime> discardL
(Applicative<_1Prime, SingletonHList<?>> appB) Sequence both thisApplicative
andappB
, discarding thisApplicative's
result and returningappB
.<_1Prime> SingletonHList
<_1> discardR
(Applicative<_1Prime, SingletonHList<?>> appB) Sequence both thisApplicative
andappB
, discardingappB's
result 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> Covariantly transmute this functor's parameter using the given mapping function.<R> R
ApplyHList.HCons.head()
tofn
and return the result.<_1Prime> Lazy
<SingletonHList<_1Prime>> lazyZip
(Lazy<? extends Applicative<Fn1<? super _1, ? extends _1Prime>, SingletonHList<?>>> lazyAppFn) Given alazy
instance 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 valueb
into this applicative functor.static Pure
<SingletonHList<?>> The canonicalPure
instance forSingletonHList
.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 aRecursiveResult
inside thisMonadRec
, internally trampoline the operation until it yields atermination
instruction.<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) 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.<_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 Details
-
SingletonHList
SingletonHList(_1 _1)
-
-
Method Details
-
cons
Cons an element onto the front of this HList.- Overrides:
cons
in classHList.HCons<_1,
HList.HNil> - 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 thisSingletonHList
.- Type Parameters:
_2
- the new last element type- Parameters:
_2
- the new last element- Returns:
- the new
Tuple2
-
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:
fmap
in interfaceApplicative<_1,
SingletonHList<?>> - Specified by:
fmap
in interfaceFunctor<_1,
SingletonHList<?>> - Specified by:
fmap
in interfaceMonad<_1,
SingletonHList<?>> - Specified by:
fmap
in interfaceMonadRec<_1,
SingletonHList<?>> - Specified by:
fmap
in 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
Lift the valueb
into this applicative functor.- Specified by:
pure
in interfaceApplicative<_1,
SingletonHList<?>> - Specified by:
pure
in interfaceMonad<_1,
SingletonHList<?>> - Specified by:
pure
in 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:
zip
in interfaceApplicative<_1,
SingletonHList<?>> - Specified by:
zip
in interfaceMonad<_1,
SingletonHList<?>> - Specified by:
zip
in 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 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<_1,
SingletonHList<?>> - Specified by:
lazyZip
in interfaceMonad<_1,
SingletonHList<?>> - Specified by:
lazyZip
in interfaceMonadRec<_1,
SingletonHList<?>> - Type Parameters:
_1Prime
- the resulting applicative parameter type- Parameters:
lazyAppFn
- the lazy other applicative instance- Returns:
- the mapped applicative
- See Also:
-
discardL
Sequence both thisApplicative
andappB
, discarding thisApplicative's
result and returningappB
. This is generally useful for sequentially performing side-effects.- Specified by:
discardL
in interfaceApplicative<_1,
SingletonHList<?>> - Specified by:
discardL
in interfaceMonad<_1,
SingletonHList<?>> - Specified by:
discardL
in interfaceMonadRec<_1,
SingletonHList<?>> - Type Parameters:
_1Prime
- the type of the returned Applicative's parameter- Parameters:
appB
- the other Applicative- Returns:
- appB
-
discardR
Sequence both thisApplicative
andappB
, discardingappB's
result and returning thisApplicative
. This is generally useful for sequentially performing side-effects.- Specified by:
discardR
in interfaceApplicative<_1,
SingletonHList<?>> - Specified by:
discardR
in interfaceMonad<_1,
SingletonHList<?>> - Specified by:
discardR
in 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:
flatMap
in interfaceMonad<_1,
SingletonHList<?>> - Specified by:
flatMap
in 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 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<_1,
SingletonHList<?>> - Type Parameters:
_1Prime
- the ultimate resulting carrier type- Parameters:
fn
- the function to internally trampoline- Returns:
- the trampolined
MonadRec
- See Also:
-
traverse
public <B,App extends Applicative<?, AppTrav traverseApp>, TravB extends Traversable<B, SingletonHList<?>>, AppTrav extends Applicative<TravB, App>> (Fn1<? super _1, ? extends Applicative<B, 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<_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
ApplyHList.HCons.head()
tofn
and 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
The canonicalPure
instance forSingletonHList
.- Returns:
- the
Pure
instance
-