Skip to content

Instantly share code, notes, and snippets.

@joecwu
Last active August 29, 2015 14:25
Show Gist options
  • Save joecwu/f0d21f27c212866f4024 to your computer and use it in GitHub Desktop.
Save joecwu/f0d21f27c212866f4024 to your computer and use it in GitHub Desktop.
Blog Scala API Document Implicit Parameter sample code. http://blog.joecwu.com/2015/07/scava-scala-scala-api-document-implicit.html
case class TracerId(tid:String)
object TestApp {
implicit val tracerId = TracerId(java.util.UUID.randomUUID().toString) // tracerId can be defined and retrieved from HTTP request header.
def run(){
methodA(1)
methodB
}
def methodA(i:Int)(implicit tracerId:TracerId) = {
println(s"A: I have tracerId:[$tracerId].")
}
def methodB(implicit tracerId:TracerId) = {
println(s"B: I have tracerId:[$tracerId].")
methodC("YOYO")
}
def methodC(str:String)(implicit tracerId:TracerId) = {
println(s"C: I have tracerId:[$tracerId] as well.")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment