@@ -28,20 +28,31 @@ 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- implicit class AsFunction [F , Args <: Tuple , R ](f : Expr [F ])(given tf : TupledFunction [F , Args => R ], qctx : QuoteContext ) {
32- /** Beta-reduces the function appication. Generates the an expression only containing the body of the function */
33- def apply [G ](given tg : TupledFunction [G , TupleOfExpr [Args ] => Expr [R ]]): G = {
34- import qctx .tasty ._
35- tg.untupled(args => qctx.tasty.internal.betaReduce(f.unseal, args.toArray.toList.map(_.asInstanceOf [QuoteContext => Expr [_]](qctx).unseal)).seal.asInstanceOf [Expr [R ]])
36- }
31+ /** `Expr.betaReduce(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.betaReduce` distributes applications of `Expr` over function arrows
35+ * ```scala
36+ * Expr.betaReduce(_): Expr[(T1, ..., Tn) => R] => ((Expr[T1], ..., Expr[Tn]) => Expr[R])
37+ * ```
38+ */
39+ def betaReduce [F , Args <: Tuple , R , G ](f : Expr [F ])(given tf : TupledFunction [F , Args => R ], tg : TupledFunction [G , TupleOfExpr [Args ] => Expr [R ]], qctx : QuoteContext ): G = {
40+ import qctx .tasty ._
41+ tg.untupled(args => qctx.tasty.internal.betaReduce(f.unseal, args.toArray.toList.map(_.asInstanceOf [QuoteContext => Expr [_]](qctx).unseal)).seal.asInstanceOf [Expr [R ]])
3742 }
3843
39- implicit class AsContextualFunction [F , Args <: Tuple , R ](f : Expr [F ])(given tf : TupledFunction [F , (given Args ) => R ], qctx : QuoteContext ) {
40- /** Beta-reduces the function appication. Generates the an expression only containing the body of the function */
41- def apply [G ](given tg : TupledFunction [G , TupleOfExpr [Args ] => Expr [R ]]): G = {
42- import qctx .tasty ._
43- tg.untupled(args => qctx.tasty.internal.betaReduce(f.unseal, args.toArray.toList.map(_.asInstanceOf [QuoteContext => Expr [_]](qctx).unseal)).seal.asInstanceOf [Expr [R ]])
44- }
44+ /** `Expr.betaReduceGiven(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.betaReduceGiven` distributes applications of `Expr` over function arrows
48+ * ```scala
49+ * Expr.betaReduceGiven(_): Expr[(given T1, ..., Tn) => R] => ((Expr[T1], ..., Expr[Tn]) => Expr[R])
50+ * ```
51+ * Note: The
52+ */
53+ def betaReduceGiven [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 = {
54+ import qctx .tasty ._
55+ tg.untupled(args => qctx.tasty.internal.betaReduce(f.unseal, args.toArray.toList.map(_.asInstanceOf [QuoteContext => Expr [_]](qctx).unseal)).seal.asInstanceOf [Expr [R ]])
4556 }
4657
4758 /** Returns a null expresssion equivalent to `'{null}` */
0 commit comments