halotukozak's small collection of Scala 3 macro and metaprogramming utilities: tuple operations
backed by type-level constraints, and typeclass-derivation factories that make FromExpr/ToExpr
derivation work recursively for generic types.
Cross-built for the JVM, Scala.js, and Scala Native. Published to Maven Central under com.halotukozak.
scala-cli:
//> using dep com.halotukozak::commons::<version>sbt:
libraryDependencies += "com.halotukozak" %% "commons" % "<version>"Tuple.to[T, C]/toArrayOf[T]— convert a tuple into any standard collection (viaFactory) or a plainArray, guarded by acontainsOnlyconstraint.Tuple.mapAs[T]— map over a tuple's elements with a function polymorphic in a shared upper boundT.Tuple.foreach,Tuple.indices,Tuple.hasDuplicates— small ergonomic additions on top ofscala.Tuple.realCons— cons an element onto a tuple while preserving its precise singleton type.containsOnly[Tup, T]— a type-level constraint proving every element ofTupconforms toT, with derivation rules forTuple.Map, covariant functors,Tail,Reverse,Concat, andZip, plus implicit conversions fromHead/Last.
FromExprFactory/ToExprFactory—deriveson any product or sum type recursively derivesFromExpr[T]/ToExpr[T]for each field/case, so generic types no longer need a hand-writtengivenfor their type parameters.- Built-in instances for
Array,Seq,List,Set,Map,Option,Some,Either/Left/Right, andTuple1throughTuple22. QuotedFactoryGivensbridges any derived factory back into the standardFromExpr/ToExprso it's picked up automatically wherever those are expected.Expr.ofRefinedTuple— build anExpr[Tuple]from aList[Expr[?]]while keeping each element's refined type.
import scala.quoted.*
case class Point(x: Int, y: Int) derives ToExprFactory, FromExprFactoryMIT