@@ -28,13 +28,28 @@ package quoted {
28
28
/** Converts a tuple `(T1, ..., Tn)` to `(Expr[T1], ..., Expr[Tn])` */
29
29
type TupleOfExpr [Tup <: Tuple ] = Tuple .Map [Tup , [X ] =>> (given QuoteContext ) => Expr [X ]]
30
30
31
- /** Beta-reduces the function appication. Generates the an expression only containing the body of the function */
31
+ /** `Expr.reduce(f)(x1, ..., xn)` is functionally the same as `'{($f)($x1, ..., $xn)}`, however it optimizes this call
32
+ * by returning the result of beta-reducing `f(x1, ..., xn)` if `f` is a known lambda expression.
33
+ *
34
+ * `Expr.reduce` distributes applications of `Expr` over function arrows
35
+ * ```scala
36
+ * Expr.reduce(_): Expr[(T1, ..., Tn) => R] => ((Expr[T1], ..., Expr[Tn]) => Expr[R])
37
+ * ```
38
+ */
32
39
def reduce [F , Args <: Tuple , R , G ](f : Expr [F ])(given tf : TupledFunction [F , Args => R ], tg : TupledFunction [G , TupleOfExpr [Args ] => Expr [R ]], qctx : QuoteContext ): G = {
33
40
import qctx .tasty ._
34
41
tg.untupled(args => qctx.tasty.internal.betaReduce(f.unseal, args.toArray.toList.map(_.asInstanceOf [QuoteContext => Expr [_]](qctx).unseal)).seal.asInstanceOf [Expr [R ]])
35
42
}
36
43
37
- /** Beta-reduces the function appication. Generates the an expression only containing the body of the function */
44
+ /** `Expr.reduceGiven(f)(x1, ..., xn)` is functionally the same as `'{($f)(given $x1, ..., $xn)}`, however it optimizes this call
45
+ * by returning the result of beta-reducing `f(given x1, ..., xn)` if `f` is a known lambda expression.
46
+ *
47
+ * `Expr.reduceGiven` distributes applications of `Expr` over function arrows
48
+ * ```scala
49
+ * Expr.reduceGiven(_): Expr[(given T1, ..., Tn) => R] => ((Expr[T1], ..., Expr[Tn]) => Expr[R])
50
+ * ```
51
+ * Note: The
52
+ */
38
53
def reduceGiven [F , Args <: Tuple , R , G ](f : Expr [F ])(given tf : TupledFunction [F , (given Args ) => R ], tg : TupledFunction [G , TupleOfExpr [Args ] => Expr [R ]], qctx : QuoteContext ): G = {
39
54
import qctx .tasty ._
40
55
tg.untupled(args => qctx.tasty.internal.betaReduce(f.unseal, args.toArray.toList.map(_.asInstanceOf [QuoteContext => Expr [_]](qctx).unseal)).seal.asInstanceOf [Expr [R ]])
0 commit comments