@@ -130,6 +130,30 @@ object Expr {
130
130
def ofList [T ](xs : Seq [Expr [T ]])(using Type [T ], QuoteContext ): Expr [List [T ]] =
131
131
if (xs.isEmpty) ' { Nil } else ' { List ($ {Varargs (xs)}: _* ) }
132
132
133
+ /** Lifts the Map the values of which are expressions into an expression of Map. */
134
+ def ofMapValues [K : Type , V : Type ](m : Map [K , Expr [V ]])(
135
+ using QuoteContext , Liftable [List [K ]]): Expr [Map [K , V ]] =
136
+ val keys : Expr [List [K ]] = Expr (m.keys.toList)
137
+ val values : Expr [List [V ]] = Expr .ofList(m.values.toList)
138
+ ' { $ { keys }.zip($ { values }).toMap }
139
+ end ofMapValues
140
+
141
+ /** Lifts the Map the keys of which are expressions into an expression of Map. */
142
+ def ofMapKeys [K : Type , V : Type ](m : Map [Expr [K ], V ])(
143
+ using QuoteContext , Liftable [List [V ]]): Expr [Map [K , V ]] =
144
+ val keys : Expr [List [K ]] = Expr .ofList(m.keys.toList)
145
+ val values : Expr [List [V ]] = Expr (m.values.toList)
146
+ ' { $ { keys }.zip($ { values }).toMap }
147
+ end ofMapKeys
148
+
149
+ /** Lifts the Map the keys and values of which are expressions into an expression of Map. */
150
+ def ofMapKeyValues [K : Type , V : Type ](m : Map [Expr [K ], Expr [V ]])(
151
+ using QuoteContext ): Expr [Map [K , V ]] =
152
+ val keys : Expr [List [K ]] = Expr .ofList(m.keys.toList)
153
+ val values : Expr [List [V ]] = Expr .ofList(m.values.toList)
154
+ ' { $ { keys }.zip($ { values }).toMap }
155
+ end ofMapKeyValues
156
+
133
157
/** Lifts this sequence of expressions into an expression of a tuple
134
158
*
135
159
* Transforms a sequence of expression
0 commit comments