Created
February 26, 2021 19:26
-
-
Save deanwampler/9dbc5564a127db949a9f061702c4a2ca 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
// 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