File tree Expand file tree Collapse file tree 5 files changed +36
-0
lines changed
library/src/scala/compiletime Expand file tree Collapse file tree 5 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,15 @@ package object compiletime {
4242
4343 inline def constValue [T ]: T = ???
4444
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+
4554 /** Summons first given matching one of the listed cases. E.g. in
4655 *
4756 * given B { ... }
@@ -68,6 +77,20 @@ package object compiletime {
6877 case t : T => t
6978 }
7079
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
7194
7295 /** Succesor of a natural number where zero is the type 0 and successors are reduced as if the definition was
7396 *
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