Skip to content

Instantly share code, notes, and snippets.

View juanjovazquez's full-sized avatar

Juan José Vázquez juanjovazquez

  • Legálitas
  • España
View GitHub Profile
@juanjovazquez
juanjovazquez / polyMatch.scala
Created May 26, 2020 08:47
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
@juanjovazquez
juanjovazquez / polyMap.scala
Created May 26, 2020 12:26
Errors using context bounded poly functions in Scala 3
package polyMap
type Id[T] = T
trait Negation[A]:
def neg(a: A): A
object Negation:
def apply[A](using ev: Negation[A]): Negation[A] = ev
@juanjovazquez
juanjovazquez / Field0.scala
Created December 20, 2021 12:45
erasedValue seems not work with opaque types
// Regular class
final case class Field0[L <: String & Singleton, V](label: L, value: V)
@juanjovazquez
juanjovazquez / Displays.scala
Created November 1, 2022 16:55
Emulating polymorphic functions on polymorphic collections
package polycol
object Displays {
import PolyCol.*
opaque type Display = String
object Display {
def apply[A: Printer](a: A): Display = a.print
}