This question is derived from my previous question: What does HList#foldLeft() return?
I have this scenario:
class Cursor {
}
trait Column[T] {
def read(c: Cursor, index: Int): T
}
object Columns {
object readColumn extends Poly2 {
implicit def a[A, B <: HList] = at[Column[A], (B, Cursor, Int)] { case (col, (values, cursor, index)) ⇒
(col.read(cursor, index) :: values, cursor, index+1)
}
}
def readColumns[A <: HList, B <: HList](c: Cursor, columns: A)(implicit l: RightFolder.Aux[A, (HNil.type, Cursor, Int), readColumn.type, (B, Cursor, Int)]): B =
columnas.foldRight((HNil, c, 0))(readColumn)._1
}
This code, tries to read the values of several columns.
If I call readColumns(cursor, new Column[String] :: new Column[Int] :: HNil)
, I expect to get String :: Int :: HNil
.
The readColumns()
method compiles ok, but the compiler complains about implicits in concrete invocations.
What is the right way of working?.
UPDATE 1:
Here is the exact error message I'm receiving when invoking with 2 columns:
could not find implicit value for parameter l:
shapeless.ops.hlist.RightFolder.Aux[shapeless.::[Column[String],shapeless.::
[Column[String],shapeless.HNil]],(shapeless.HNil.type, android.database.Cursor, Int),readColumn.type,(B, android.database.Cursor, Int)]
Don't know how to help the compiler. :-(
UPDATE 2:
Question: why specify HNil.type
in the implicit parameter of readColumns()
: RightFolder.Aux[A, (HNil.type, Cursor, Int), readColumn.type, (B, Cursor, Int)]
?