Skip to content

Instantly share code, notes, and snippets.

@kevinwright
Created July 10, 2012 12:19
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinwright/3082959 to your computer and use it in GitHub Desktop.
Save kevinwright/3082959 to your computer and use it in GitHub Desktop.
Typesafe conversion from List[Any] to a case class, via shapeless
case class ZeeingEvent(
zid: String,
kind: String,
showId: String,
show_name: Option[String],
time: DateTime
) {
require (kind == "StartedZeeing" || kind == "EndedZeeing")
}
object ZeeingEvent {
implicit val iso = HListIso(ZeeingEvent.apply _, ZeeingEvent.unapply _)
def fromList(l: List[Any]): ZeeingEvent = {
def toHList[HL <: HList](
implicit
iso: HListIso[ZeeingEvent, HL],
typeable: Typeable[HL]
): Option[HL] =
l.cast[HL]
toHList map {iso.fromHList} getOrElse {
sys.error("couldn't parse list as zeeing event: " + l)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment