https://github.com/scytrowski/mat
Lightweight Scala 3 library for materializing types into values at compile time.
https://github.com/scytrowski/mat
compiletime scala scala3 typelevel typelevel-programming
Last synced: 18 days ago
JSON representation
Lightweight Scala 3 library for materializing types into values at compile time.
- Host: GitHub
- URL: https://github.com/scytrowski/mat
- Owner: scytrowski
- License: mit
- Created: 2025-06-28T00:03:00.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-07-03T22:16:14.000Z (7 months ago)
- Last Synced: 2025-07-03T23:25:13.486Z (7 months ago)
- Topics: compiletime, scala, scala3, typelevel, typelevel-programming
- Language: Scala
- Homepage:
- Size: 24.4 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mat
[](https://www.scala-lang.org)
[](https://mvnrepository.com/artifact/io.github.scytrowski/mat_3)
[](LICENSE)
**`mat`** is a lightweight Scala 3 library for materializing types into values at compile time.
It provides a typeclass-based approach for turning types like tuples, literal types, or case classes into values using `inline` and `Mirror`.
---
## ✨ Features
- Materialize literal types like `5`, `"hello"`, `true`
- Recursively materialize tuples: `(1, "abc", true)`
- Materialize case classes via `Mirror.ProductOf`
- Materialize singleton sealed trait based ADTs via `Mirror.SumOf`
- Safe fallback with `materializeOpt[A]` returning `Option`
---
## 📦 Examples
### Materialize a literal value
```scala
import io.github.scytrowski.mat.*
val x: 42 = materialize[42]
// x: 42
```
### Materialize a tuple
```scala
import io.github.scytrowski.mat.*
val x: (true, 'd', "abc") = materialize[(true, 'd', "abc")]
// x: (true, 'd', "abc")
```
### Materialize a case object
```scala
import io.github.scytrowski.mat.*
case object SomeObject
val x: SomeObject.type = materialize[SomeObject.type]
// x: SomeObject
```
### Materialize a case class
```scala
import io.github.scytrowski.mat.*
case class SomeClass[A](a: A)
val x: SomeClass[15] = materialize[SomeClass[15]]
// x: SomeClass(15)
```
### Materialize a singleton ADT variant
```scala
import io.github.scytrowski.mat.*
sealed trait SomeADT
case object SingletonVariant extends SomeADT
val x: SingletonVariant.type = materialize[SomeADT]
// x: SingletonVariant
```
### Provide custom materialization logic
```scala
import io.github.scytrowski.mat.*
sealed abstract class SomeClass
object SomeClass:
val instance: SomeClass = new SomeClass {}
given CustomMaterialize[SomeClass]:
override type Out = SomeClass
override def apply(): SomeClass = SomeClass.instance
val x: SomeClass = materialize[SomeClass]
// x: SomeClass.instance
```
### Require a materializable type
```scala
import io.github.scytrowski.mat.*
def doSomethingWithMaterializableType[A: Materialize] = ???
```
---
## 🚧 TODO
- [ ] Support intersection types - e.g.: `5 & Int` should materialize as `5`
- [ ] Support union types - e.g.: `5 | String` should materialize as `5`
- [ ] Support nested singleton ADTs
---
## 📄 License
This project is licensed under the [MIT License](LICENSE).
You are free to use, copy, modify, and distribute it with attribution.