Skip to content

Instantly share code, notes, and snippets.

@talesin
Last active August 23, 2016 22:48
Show Gist options
  • Save talesin/fcf15c12384bebf44241cfb92f090a87 to your computer and use it in GitHub Desktop.
Save talesin/fcf15c12384bebf44241cfb92f090a87 to your computer and use it in GitHub Desktop.
import shapeless._
object PrintPoly extends Poly1 {
implicit def default[T] = at[(String,T)](_ match {
case (s, Some(x)) => () => println(s"option: $s = $x")
case (s, None) => () => println(s"option: $s = None")
case (s, x) => () => println(s"normal: $s = $x")
})
}
object StringPoly extends Poly1 {
implicit def default[T] = at[(String,T)](_ match {
case (s, Some(x)) => s"option: $s = $x"
case (s, None) => s"option: $s = None"
case (s, x) => s"normal: $s = $x"
})
}
val list = ("title", "the job title") :: ("id", 99) :: ("isactive", true) :: ("property", Some("value")) :: ("property2", None) :: HNil
list.map(PrintPoly).toList.foreach { _ () }
list.map(StringPoly).toList.foreach { println }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment