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 / 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
}
@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 / 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 / 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
// For educational purposes
object MyListModule {
trait MyList[+A]
object MyList {
case object Empty extends MyList[Nothing]
case class Cons[A](h: A, t: MyList[A]) extends MyList[A]
def head[A](l: MyList[A]): A =
@juanjovazquez
juanjovazquez / shape1.scala
Last active March 8, 2020 07:51
Records à la shapeless in dotty
object labelled {
opaque type Field[K <: String, +V] = V
object Field {
def apply[K <: String, V](v: V): Field[K, V] = v
extension on [K <: String, V](field: Field[K, V]) {
def value: V = field
}
}

Keybase proof

I hereby claim:

  • I am juanjovazquez on github.
  • I am juanjovazquez (https://keybase.io/juanjovazquez) on keybase.
  • I have a public key ASA_XoOdzNnmX2_GFOJ-PXZKlDlhZg6iuTiQGYNIGTdq-Ao

To claim this, I am signing this object:

@juanjovazquez
juanjovazquez / iotaGen.scala
Last active February 5, 2018 09:34
Scalacheck generator for iota coproduct (No longer necessary after this http://bit.ly/2EFdY4k)
// This is an ammonite scala script see: http://bit.ly/2FyQf58
// Dependencies
import $ivy.`org.typelevel::cats-core:1.0.1`
import $ivy.`com.chuusai::shapeless:2.3.3`
import $ivy.`io.frees::iota-core:0.3.4`
import $ivy.`org.scalacheck::scalacheck:1.13.5`
// Regular imports
import iota.{ Cop, TNil }
import cats.~>
import cats.data.State
import cats.syntax.all._
import org.atnos.eff.{ |=, <=, Eff, Fx, Member }
import org.atnos.eff.state.get
import org.atnos.eff.either.fromEither
import org.atnos.eff.Eff.send
import org.atnos.eff.Interpret.translateNat
import org.atnos.eff.syntax.all._
@juanjovazquez
juanjovazquez / raptureXmlTest.scala
Last active March 5, 2017 12:12
Rapture: XML extraction problem
object RaptureXmlOk {
import rapture.xml._
case class Foo(bar: Bar)
case class Bar(baz: Baz)
case class Baz(qux: Qux)
case class Qux(value: String)
implicitly[Extractor[Bar, Xml]] // works
implicitly[Extractor[Foo, Xml]] // works