Thậm chí .head
không hoạt động.Tại sao tôi không thể lập chỉ mục vào một HList thu được bằng cách ánh xạ trên một HList khác?
Tôi cần phải thực hiện những thay đổi gì để thực hiện công việc này?
import shapeless._
import HList._
import Nat._
scala> case class Foo[A](a: A)
defined class Foo
scala> case class Bar[A](f: Foo[A])
defined class Bar
scala> val xs = Foo(23) :: Foo("blah") :: HNil
xs: shapeless.::[Foo[Int],shapeless.::[Foo[java.lang.String],shapeless.HNil]] = Foo(23) :: Foo(blah) :: HNil
scala> object mapper extends (Foo ~> Bar) {
| def apply[A](f: Foo[A]) = Bar(f)
| }
defined module mapper
scala> xs map mapper
res13: mapper.Out = Bar(Foo(23)) :: Bar(Foo(blah)) :: HNil
scala> res13.apply[_1]
<console>:38: error: could not find implicit value for parameter at: shapeless.At[mapper.Out,shapeless.Nat._1]
res13.apply[_1]
^
scala> res13.head
<console>:38: error: could not find implicit value for parameter c: shapeless.IsHCons[mapper.Out]
res13.head
^