@@ -28,13 +28,28 @@ package quoted {
2828 /** Converts a tuple `(T1, ..., Tn)` to `(Expr[T1], ..., Expr[Tn])` */
2929 type TupleOfExpr [Tup <: Tuple ] = Tuple .Map [Tup , [X ] =>> (given QuoteContext ) => Expr [X ]]
3030
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+ */
3239 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 = {
3340 import qctx .tasty ._
3441 tg.untupled(args => qctx.tasty.internal.betaReduce(f.unseal, args.toArray.toList.map(_.asInstanceOf [QuoteContext => Expr [_]](qctx).unseal)).seal.asInstanceOf [Expr [R ]])
3542 }
3643
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+ */
3853 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 = {
3954 import qctx .tasty ._
4055 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