Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save deanwampler/9dbc5564a127db949a9f061702c4a2ca to your computer and use it in GitHub Desktop.
Save deanwampler/9dbc5564a127db949a9f061702c4a2ca to your computer and use it in GitHub Desktop.
// Type parameter placeholder: S[_]
def str[T, S[_]](ss: S[T]): String = ss.toString
val s1 = str(Seq(1, 2, 3)) // "List(1, 2, 3)"
// Function parameter placeholder: _.toUpperCase
val loud = Seq("hello world!").map(_.toUpperCase) // List(HELLO WORLD!)
// Match placeholder: _ in the first two case clauses
Seq(Seq('a', 'b', 'c'), Seq(1, 2, 3), Seq(1.1, 2.2)).map {
seq => seq match {
case 'a' +: _ => "Found a"
case head +: _ +: last +: _ => s"Found $head and $last"
case head +: tail => s"Other list: $seq"
}
} // List("Found a", "Found 1 and 3", "Other list: List(1.1, 2.2)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment