Last active
April 28, 2021 15:17
-
-
Save deanwampler/5f7e807f71586ca48151b6426b48b050 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
scala> val seq = Seq(1, 2, 3.14, 5.5F, "one", "four", true, (6, 7)) | |
| | |
val seq: Seq[Matchable] = List(1, 2, 3.14, 5.5, one, four, true, (6,7)) | |
scala> val result = seq.map { | |
| case 1 => "int 1" // <2> | |
| case i: Int => s"other int: $i" | |
| case d: (Double | Float) => s"a double or float: $d" // <3> | |
| case "one" => "string one" // <4> | |
| case s: String => s"other string: $s" | |
| case (x, y) => s"tuple: ($x, $y)" // <5> | |
| case unexpected => s"unexpected value: $unexpected" // <6> | |
| } | |
| | |
val result: Seq[String] = List(int 1, other int: 2, a double or float: 3.14, a double or float: 5.5, string one, other string: four, unexpected value: true, tuple: (6, 7)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment