Skip to content

Instantly share code, notes, and snippets.

@juanjovazquez
Created May 26, 2020 08:47
Show Gist options
  • Select an option

  • Save juanjovazquez/be0cb3bd1206380edc288c3539f03854 to your computer and use it in GitHub Desktop.

Select an option

Save juanjovazquez/be0cb3bd1206380edc288c3539f03854 to your computer and use it in GitHub Desktop.
Scala 3 poly functions on match types
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