scala - HList as parameter of method with simplified type signature -
suppose have container-marker
case class typedstring[t](value: string) where value represents id particular type t.
i have 2 classes
case class user(id: string) case class event(id: string) and have function stuff:
def func[l <: hlist](l: l)(...) {...} so can use
func[typedstring[user] :: typedstring[event] :: hnil]( typedstring[user]("user id") :: typedstring[event]("event id") :: hnil ) (it's important me keep type signature explicitly)
the question is: how change or extends func have shorter type signature (keeping marker types) like:
func[user :: event :: hnil]( typedstring[user]("user id") :: typedstring[event]("event id") :: hnil )
the shapeless.ops.hlist.mapped type class gives relation of 1 hlist l , hlist elements of l wrapped in type constructor.
because have 2 types, type l want specify , type (the elements of l wrapped in typedstring), need use same trick used in your previous question (then because didn't want supply arguments @ once, because want specify first type).
import shapeless._ import ops.hlist.mapped def func[l <: hlist] = new partfunc[l] class partfunc[l <: hlist] { def apply[m <: hlist](m: m)(implicit mapped: mapped.aux[l, typedstring, m]): m = m } now can use func wanted :
func[user :: event :: hnil]( typedstring[user]("user id") :: typedstring[event]("event id") :: hnil ) // typedstring[user] :: typedstring[event] :: hnil = // typedstring(user id) :: typedstring(event id) :: hnil
Comments
Post a Comment