Finally, finally, you can work it out. What I was was a way to conditionally add to an HList . Basically, multiple overloads of the same method should coexist because they return a different type of HList .
To have only one method, arguments are needed to determine what the final signature of the method looks like.
So, suppose the following, the test method should have returned
def test[RR](arg: Type1[RR]): Wrapper[RR :: ExistingHList]
Or accordingly:
def test(arg: Type2): Wrapper[ExistingList]
The same method must be added to the HList depending on whether the argument satisfies certain conditions. The fix was as trivial as using shapeless.ops.hlist.Prepend , which by default returns an existing HList if we try to add HNil to the hlist.
Creating a Type2 argument returns HNil or implicitly converting to what will eventually be HNil - this is the approach that worked.
In particular:
class Wrapper[PS <: HList] { def test[ RR, HL <: HList, Out <: HList ]( condition: T => Wrapper[HL] )(implicit prepend: Prepend.Aux[HL, PS, Out]): Wrapper[Out[ }
This approach works if the condition function returns Wrapper[HNil] for situations where the function does not need to change the type of the return end. Functions that change can freely create their own HList their own.
source share