-
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.
synthesize mirrors for small generic tuples
- Loading branch information
1 parent
ee9cc8f
commit 8f55301
Showing
6 changed files
with
90 additions
and
25 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
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
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
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,6 @@ | ||
import scala.deriving.Mirror | ||
|
||
val mT23 = summon[Mirror.Of[( | ||
Int *: Int *: Int *: Int *: Int *: Int *: Int *: Int *: Int | ||
*: Int *: Int *: Int *: Int *: Int *: Int *: Int *: Int *: Int | ||
*: Int *: Int *: Int *: Int *: Int *: EmptyTuple)]] // error |
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,14 @@ | ||
import scala.deriving.Mirror | ||
|
||
@main def Test = | ||
val mISB = summon[Mirror.Of[Int *: String *: Boolean *: EmptyTuple]] | ||
assert(mISB.fromProduct((1, "foo", true)) == (1, "foo", true)) | ||
|
||
val mT22 = summon[Mirror.Of[( | ||
Int *: Int *: Int *: Int *: Int *: Int *: Int *: Int *: Int | ||
*: Int *: Int *: Int *: Int *: Int *: Int *: Int *: Int *: Int | ||
*: Int *: Int *: Int *: Int *: EmptyTuple)]] | ||
|
||
// tuple of 22 elements | ||
val t22 = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22) | ||
assert(mT22.fromProduct(t22) == t22) |
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,18 @@ | ||
import scala.deriving._ | ||
|
||
case class Foo(x: Int, y: String) | ||
|
||
def toTuple[T <: Product](x: T)(using m: Mirror.ProductOf[T], mt: Mirror.ProductOf[m.MirroredElemTypes]) = | ||
mt.fromProduct(x) | ||
|
||
@main def Test = { | ||
val m = summon[Mirror.ProductOf[Foo]] | ||
val mt1 = summon[Mirror.ProductOf[(Int, String)]] | ||
type R = (Int, String) | ||
val mt2 = summon[Mirror.ProductOf[R]] | ||
val mt3 = summon[Mirror.ProductOf[m.MirroredElemTypes]] | ||
|
||
val f = Foo(1, "foo") | ||
val g: (Int, String) = toTuple(f)// (using m, mt1) | ||
assert(g == (1, "foo")) | ||
} |