这不编译,我不明白为什么:
import shapeless._
import poly._
object option extends (Option ~> List) {
def apply[T](t: Option[T]) = t.toList
}
val simple = Some(1) :: Some("hello") :: Some(true) :: HNil
val opts: List[Int] :: List[String] :: List[Boolean] :: HNil = simple map option
这有点令人惊讶,因为它确实编译:
import shapeless._
import poly._
object choose extends (Set ~> Option) {
def apply[T](s: Set[T]) = s.headOption
}
val sets = Set(1) :: Set("foo") :: HNil
val opts: Option[Int] :: Option[String] :: HNil = sets map choose