@akala/core
Version:
57 lines • 2.2 kB
JavaScript
import { Expression } from './expression.js';
import { ExpressionType } from './expression-type.js';
/**
* Represents a typed lambda expression.
* @template T - The type of the lambda function.
*/
export class TypedLambdaExpression extends Expression {
body;
/** @override */
get type() { return ExpressionType.LambdaExpression; }
/** All parameters defined for this lambda expression */
parameters;
/**
* Initialize a new typed lambda expression instance
* @param {Expressions} body - Expression representing the lambda's execution logic
* @param {Parameters<T>} parameters - List of parameter definitions for this lambda
*/
constructor(body, ...parameters) {
super();
this.body = body;
this.parameters = parameters;
}
/**
* Accepts an expression visitor as part of the visitor pattern
* @param visitor - Visitor instance implementing the lambda visitation logic
*/
accept(visitor) {
return visitor.visitLambda(this);
}
}
/**
* Represents a lambda expression.
*/
export class LambdaExpression extends TypedLambdaExpression {
body;
/**
* Creates a strongly-typed lambda expression instance.
* @template T - The function type representing the lambda's signature.
* @template U - The return type of the lambda function.
* @param {TypedExpression<U>} body - The expression representing the lambda's body.
* @param {Parameters<T>} parameters - Array of parameter expressions matching the function's signature.
* @returns {TypedLambdaExpression<T>} A new typed lambda expression instance.
*/
static typed(body, parameters) {
return new TypedLambdaExpression(body, ...parameters);
}
/**
* Creates a new LambdaExpression instance.
* @param {Expressions} body - The expression tree representing the lambda's execution logic.
* @param {...Parameters<(...args: unknown[]) => unknown>} parameters - List of parameter expressions defining the lambda's input.
*/
constructor(body, ...parameters) {
super(body, ...parameters);
this.body = body;
}
}
//# sourceMappingURL=lambda-expression.js.map