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 basically do what I want; however, it seems I am getting a meaningless result:
scala> simpleRec(List.empty[List[Int]]) res3: Option[B] = None scala> simpleRec(List(List(1))) res4: Option[B] = Some(Some(1))
How can I get this to give the values of Option[Option[Int]] rather than Option[B] ? I expect that I will make a stupid mistake here, but I can’t understand what it is.
source share