Suppose I have something like this:
trait Cursor { } trait Column[T] { def read(cusor: Cursor): T } trait ColumnReader { def readColumns(columns: Product[Column[_]], cursor: Cursor): Iterable[Any] = { for (column <- columns) yield column.read(cursor) } }
The problem with the readColumns() API is that I am losing type information, i.e. if i have this:
object columnString extends Column[String] { def read(cursor: Cursor): String = ... } object columnInt extends Column[Int] { def read(cursor: Cursor): Int = ... }
An expression of type new ColumnReader().readColumns((columnString, columnInt)) returns Iterable[Any] . I would like to return something printed as Tuple2[String, Int] , but I donβt know how to do it. I am losing type information useful to the compiler.
Maybe a library like Shapeless might be useful.
I am sure Scala has some tool to solve such problems.
Any ideas?
source share