1
votes

I want to convert some case class into HList, then zip with index the returned HList and then map it with indexes:

class B[A]() {    
  def foo[H <: HList](tuple: A)(implicit gen: Generic.Aux[A, H],
                                               zip: ZipWithIndex[H],
                                               mapper: Mapper[UpdateOps.type, ZipWithIndex[H]#Out]) = {
    gen.to(tuple).zipWithIndex.map(UpdateOps)
  }
}

Where UpdateOps is a package object:

 object UpdateOps extends Poly1 {
    ??? // not implemented yet
  }

The problem is that i got a compile error:

Error:(24, 35) could not find implicit value for parameter mapper: shapeless.ops.hlist.Mapper[UpdateOps.type,zip.Out] gen.to(tuple).zipWithIndex.map(UpdateOps) Error:(24, 35) not enough arguments for method map: (implicit mapper: shapeless.ops.hlist.Mapper[UpdateOps.type,zip.Out])mapper.Out. Unspecified value parameter mapper. gen.to(tuple).zipWithIndex.map(UpdateOps)

If i just map HList then there is no errors, but i need to save indexes. Is it possible to achieve it?

1

1 Answers

2
votes

You can use the Aux pattern to use the output type of an implicitly resolved type as the input type of the next one:

class B[A]() {
  def foo[
  H <: HList,
  Z <: HList,
  O <: HList](tuple: A)
             (implicit gen: Generic.Aux[A, H],
              zip: ZipWithIndex.Aux[H, Z],
              mapper: Mapper.Aux[UpdateOps.type, Z, O]): O = {
    gen.to(tuple).zipWithIndex.map(UpdateOps)
  }
}