Last active
August 23, 2016 22:48
-
-
Save talesin/fcf15c12384bebf44241cfb92f090a87 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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