Skip to content

Instantly share code, notes, and snippets.

@tixxit
Last active August 29, 2015 13:57
Show Gist options
  • Save tixxit/9789854 to your computer and use it in GitHub Desktop.
Save tixxit/9789854 to your computer and use it in GitHub Desktop.
import shapeless._
import shapeless.ops.traversable._
trait ListApply[A] {
def apply(xs: List[_]): Option[A]
}
object ListApply {
implicit def genericListApply[A, L <: HList](gen: Generic.Aux[A, L], toHList: FromTraversable[L]) =
new ListApply[A] {
def apply(xs: List[_]): Option[A] = toHList(xs) map gen.from
}
def apply[A](xs: List[_])(implicit toA: ListApply[A]): Option[A] = toA(xs)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment