File tree 5 files changed +36
-0
lines changed
library/src/scala/compiletime
5 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,15 @@ package object compiletime {
42
42
43
43
inline def constValue [T ]: T = ???
44
44
45
+ inline def constValueTuple [T <: Tuple ]: T =
46
+ val res =
47
+ inline erasedValue[T ] match
48
+ case _ : EmptyTuple => EmptyTuple
49
+ case _ : (t *: ts) => constValue[t] *: constValueTuple[ts]
50
+ end match
51
+ res.asInstanceOf [T ]
52
+ end constValueTuple
53
+
45
54
/** Summons first given matching one of the listed cases. E.g. in
46
55
*
47
56
* given B { ... }
@@ -68,6 +77,20 @@ package object compiletime {
68
77
case t : T => t
69
78
}
70
79
80
+ /** Given a tuple T, summons each of its member types and returns them in
81
+ * a List.
82
+ *
83
+ * @tparam T the tuple containing the types of the values to be summoned
84
+ * @return the given values typed as elements of the tuple
85
+ */
86
+ inline def summonAll [T <: Tuple ]: T =
87
+ val res =
88
+ inline erasedValue[T ] match
89
+ case _ : EmptyTuple => EmptyTuple
90
+ case _ : (t *: ts) => summonInline[t] *: summonAll[ts]
91
+ end match
92
+ res.asInstanceOf [T ]
93
+ end summonAll
71
94
72
95
/** Succesor of a natural number where zero is the type 0 and successors are reduced as if the definition was
73
96
*
Original file line number Diff line number Diff line change
1
+ (foo,bar,10,2.5)
Original file line number Diff line number Diff line change
1
+ import compiletime .constValueTuple
2
+
3
+ @ main def Test =
4
+ println(constValueTuple[" foo" *: " bar" *: 10 *: 2.5 *: EmptyTuple ])
Original file line number Diff line number Diff line change
1
+ (10,foo,1.2)
Original file line number Diff line number Diff line change
1
+ import compiletime .summonAll
2
+
3
+ @ main def Test =
4
+ given as Int = 10
5
+ given as String = " foo"
6
+ given as Double = 1.2
7
+ println(summonAll[Int *: String *: Double *: EmptyTuple ])
You can’t perform that action at this time.
0 commit comments