Skip to content

Instantly share code, notes, and snippets.

View ghostdogpr's full-sized avatar

Pierre Ricadat ghostdogpr

View GitHub Profile
@ghostdogpr
ghostdogpr / Derivation.scala
Last active February 8, 2025 08:46
Sum Type Derivation
import scala.annotation.nowarn
import scala.deriving.Mirror
trait TC[A] {
def show(a: A): Unit
}
@nowarn
inline def gen[A](using m: Mirror.SumOf[A]): TC[A] = {
val subTypes = compiletime.summonAll[Tuple.Map[m.MirroredElemTypes, TC]]
import com.esotericsoftware.kryo.io.{Input, Output}
import com.twitter.chill.{KSerializer, Kryo}
import scala.runtime.LazyVals
import scala.runtime.LazyVals.LazyValControlState
class LazyValControlStateSerializer extends KSerializer[LazyValControlState] {
override def read(kryo: Kryo, input: Input, cls: Class[LazyValControlState]): LazyValControlState = {
kryo.readClassAndObject(input).asInstanceOf[LazyValControlState]
}