Skip to content

Instantly share code, notes, and snippets.

@hn5092
Created April 1, 2016 05:55
Show Gist options
  • Save hn5092/a6f60cfb42c626fbd516485954bc73d3 to your computer and use it in GitHub Desktop.
Save hn5092/a6f60cfb42c626fbd516485954bc73d3 to your computer and use it in GitHub Desktop.
reduce is args is head,s fold
object common extends App {
val a = "s"
println(s"wo kao $a")
case class Foo(val name: String, val age: Int, val sex: Symbol)
val fooList = Foo("Hugh Jass", 25, 'male) ::
Foo("Biggus Dickus", 43, 'male) ::
Foo("Incontinentia Buttocks", 37, 'female) ::
Nil
println(fooList)
val stringList = fooList.foldLeft(List[String]()) { (z, f) =>
val title = f.sex match {
case 'male => "Mr."
case 'female => "Ms."
}
z :+ s"$title ${f.name}, ${f.age}"
}
println(stringList)
println(stringList(0))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment