Skip to content

halotukozak/made

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

306 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

M&DE

Mirror Annotations & Default Extraction — a Scala 3 macro library that extends scala.deriving.Mirror with annotation metadata, default values, generated members, and transparent wrapper support.

Overview

Scala 3's built-in Mirror provides basic type-level information about case classes and enums, but it stops short of exposing annotations, default values, or computed members. M&DE fills that gap — it derives enriched mirrors at compile time that carry:

  • Type-level annotation metadata — custom annotations on types and fields, queryable at both type level and runtime
  • Default value extraction — from constructor defaults, @whenAbsent annotations, and @optionalParam markers
  • Generated members@generated vals and defs exposed as first-class elements of the mirror
  • Transparent wrappers@transparent single-field case classes with compile-time wrap/unwrap
  • Custom labels@name to override the label of a type or field

Made supports case classes, enums, sealed traits, objects, value classes, and higher-kinded types.

Installation

M&DE is published to Maven Central under io.github.halotukozak. Requires Scala 3.

scala-cli

//> using scala 3.8.4-RC2
//> using dep io.github.halotukozak::made::0.1.0

sbt

scalaVersion := "3.8.4-RC2"
libraryDependencies += "io.github.halotukozak" %% "made" % "0.1.0"

mill

def scalaVersion = "3.8.4-RC2"
def mvDeps = Seq(mvn"io.github.halotukozak::made::0.1.0")

Quickstart

Derive a Made mirror for a case class and inspect its fields, labels, and annotations.

import made.*
import made.annotation.*

case class User(@name("user_name") name: String, age: Int = 18)

val mirror = Made.derived[User]

// Type-level
//   mirror.Label       =:= "User"
//   mirror.ElemLabels  =:= ("user_name", "age")
//   mirror.ElemTypes   =:= (String, Int)

// Runtime
val (nameElem, ageElem) = mirror.elems
nameElem.label  // "user_name"
ageElem.default // Some(18)

// Build values
val u = mirror.fromUnsafeArray(Array("Alice", 30))

See the guides for full coverage of deriving type classes, default extraction, generated members, and transparent wrapping.

Acknowledgements

M&DE is inspired by:

About

Mirror Annotations & Default Extraction. A Scala 3 macro library that extends scala.deriving.Mirror with annotation metadata, default values, generated members, and transparent wrapper support.

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages