Skip to content

Instantly share code, notes, and snippets.

@nicktelford
Created September 24, 2012 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicktelford/3775329 to your computer and use it in GitHub Desktop.
Save nicktelford/3775329 to your computer and use it in GitHub Desktop.
object App {
case class Post(title: String,
body: String,
tags: List[String])
case class Address(street: String,
city: String,
state: String,
zip: String,
tags: List[String])
type Taggable = { def tags: List[String] }
def formattedTags(taggable: Taggable) = {
taggable.tags.mkString(",")
}
def main(args: Array[String]) {
val post = Post("Weekly NFL Scores",
"This week...",
List("news", "sports", "local"))
println(formattedTags(post)) // news,sports,local
val address = Address("1 Main St.",
"Anytown",
"CA",
"12345",
List("home", "work"))
println(formattedTags(address)) // home,work
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment