I've constructed the following:
import shapeless._
import poly._
object Main {
def main(args: Array[String]) = {
object iterateOverHList extends (List ~> Iterator) {
def apply[T](it: List[T]) = it.iterator
}
val x = List(1,2,3) :: List("cat","dog") :: HNil
val xIt = x map iterateOverHList
}
}
The above code works great and is awesome. However, I still want more. I would like to, rather than specifying that my HList will contain Lists, allow any Iterable. Like this:
import shapeless._
import poly._
object Main {
def main(args: Array[String]) = {
object iterateOverHList extends (Iterable ~> Iterator) {
def apply[T](it: Iterable[T]) = it.iterator
}
val x = List(1,2,3) :: List("cat","dog") :: HNil
val xIt = x map iterateOverHList
}
}
This second version fails to compile, with the message "could not find implicit value for parameter mapper: shapeless.ops.hlist.Mapper[iterateOverHList.type,shapeless.::[List[Int],shapeless.::[List[String],shapeless.HNil]]]". The subtype polymorphism I'm expecting here, that a function that works on Iterable should work on List, is failing for some reason. Why is that? Is there a way for me to get around this problem, or will my own greed be my undoing?