-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import scala.quoted.{Expr, Quotes, Type} | ||
|
||
object Converter { | ||
private def handleUnit[R](f: Expr[Int ?=> R])(using q: Quotes, rt: Type[R]): Expr[Unit] = '{} | ||
|
||
class UnitConverter[R] extends Converter[EmptyTuple, R, Int ?=> R] { | ||
inline def convert(inline f: Int ?=> R): Unit = ${ handleUnit[R]('f) } | ||
} | ||
|
||
inline given unitHandler[R]: UnitConverter[R] = new UnitConverter[R] | ||
} | ||
|
||
|
||
trait Converter[T <: Tuple, R, F] { | ||
inline def convert(inline fn: F): Unit | ||
} | ||
|
||
abstract class Directive[R <: Tuple] { | ||
inline def apply[O, F](using inline c: Converter[R, O, F])(inline fn: F): Unit = | ||
c.convert(fn) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
object Meow extends App { | ||
case class Meow(s: String, i: Int) | ||
|
||
val dir: Directive[EmptyTuple] = ??? | ||
dir { | ||
Meow("asd", 123) | ||
} | ||
} |