Created
May 26, 2020 08:47
-
-
Save juanjovazquez/be0cb3bd1206380edc288c3539f03854 to your computer and use it in GitHub Desktop.
Scala 3 poly functions on match types
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 Negate[X] = X match | |
| case String => String | |
| case Int => Int | |
| case Boolean => Boolean | |
| def negate[A](a: A): Negate[A] = a match | |
| case x: String => s"no-$x" | |
| case x: Int => -x | |
| case x: Boolean => !x | |
| val t = (10, "foo", true) | |
| val t1 = t.map[Negate]([T] => (x: T) => negate(x)) | |
| println(t1) | |
| // (-10, no-foo, false) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment