Skip to content

Instantly share code, notes, and snippets.

View propensive's full-sized avatar

Jon Pretty propensive

View GitHub Profile
object Unpack:
import scala.quoted._
import scala.compiletime._
private def tupleType(s: String)(using q: Quotes): q.reflect.TypeRepr =
import q.reflect._
val typeParams =
s.map{ c =>
TypeRepr.of(using ConstantType(CharConstant(c)).asType)
}.toList

A short journey through types in Scala

(based on the Jon Pretty's "Advanced Type Mechanics" workshop)

Type

It is a named collection of method signatures. Those method signatures are called properties.

Classes and traits vs types

We should be careful not to confuse classes or traits and types, because they are different things. Every class and trait gives rise to a type with the same name, but in itself is not a type. Many types also exist which do not solely correspond to a trait or a class.

@propensive
propensive / DiffableDerivation.scala
Created December 23, 2018 05:18 — forked from Fristi/DiffableDerivation.scala
specs2 `Diffable` magnolia derivation
import magnolia.{CaseClass, Magnolia, SealedTrait}
import org.specs2.matcher.describe._
import scala.language.experimental.macros
object DiffableDerivation {
/** binds the Magnolia macro to this derivation object */
implicit def genDiffable[T]: Diffable[T] = macro Magnolia.gen[T]