It depends on your use case.
HList is useful for type type code, so you must pass your method not only to HList , but also all the necessary information:
def hFunc[L <: HList](hlist: L)(implicit h1: Helper1[L], h2: Helper2[L]) { // here is some code }
For example, if you want reverse to get the result of HList and map , you should use Mapper and reverse as follows:
import shapeless._, shapeless.ops.hlist.{Reverse, Mapper} object negate extends Poly1 { implicit def caseInt = at[Int]{i => -i} implicit def caseBool = at[Boolean]{b => !b} implicit def caseString = at[String]{s => "not " + s} } def hFunc[L <: HList, Rev <: HList](hlist: L)( implicit rev: Reverse[L]{ type Out = Rev }, map: Mapper[negate.type, Rev]): map.Out = map(rev(hlist)) // or hlist.reverse.map(negate)
Using:
hFunc(HList(1, true, "String")) //String :: Boolean :: Int :: HNil = not String :: false :: -1 :: HNil
senia
source share