I can write a simple recursive polymorphic function:
object simpleRec extends Poly1 {
implicit def caseInt = at[Int](identity)
implicit def caseList[A, B](implicit ev: simpleRec.Case.Aux[A, B]) =
at[List[A]](_.headOption.map(simpleRec))
}
This seems to largely do what I want; however, I seem to be getting a nonsensical result type:
scala> simpleRec(List.empty[List[Int]])
res3: Option[B] = None
scala> simpleRec(List(List(1)))
res4: Option[B] = Some(Some(1))
How can I make this give me values of Option[Option[Int]]
rather than Option[B]
? I expect I'm making some silly mistake here, but can't work out what it is.
This probably was a bug, the following code works as expected:
object simpleRec extends Poly1 {
implicit def caseInt = at[Int](identity)
implicit def caseList[A](implicit ev: simpleRec.Case[A]) =
at[List[A]](_.headOption.map(simpleRec))
}
Using shapeless_2.11-2.0.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With