~>
works with exact types. If you want a Poly1
for any subtype of Iterable
you should create it like this:
object iterateOverHList extends Poly1 {
implicit def iterable[T, L[T] <: Iterable[T]] = at[L[T]](_.iterator)
}
You could also create a Poly1
that works on some types that could be treated as Iterable
like this:
import scala.collection.generic.IsTraversableOnce
object iterateOverHList extends Poly1 {
implicit def iterable[L](implicit i: IsTraversableOnce[L]) =
at[L](i.conversion(_).toIterator)
}
val x = "abc" :: List(1,2,3) :: HNil
val xIt = x map iterateOverHList
// xIt: shapeless.::[Iterator[Char],shapeless.::[Iterator[Int],shapeless.HNil]] = non-empty iterator :: non-empty iterator :: HNil