@samatawy/rules
    Preparing search index...

    Class LambdaExpression

    A LambdaExpression represents an anonymous function that takes a single variable as input and returns a value based on an expression. The variable name is used within the expression to refer to the input value of the lambda function. Lambda expressions are commonly used in array functions like map or filter to define the transformation or condition applied to each element of the array.

    N.B. Lambda expressions are not standalone functions and cannot be called directly. They are meant to be used as arguments to higher-order functions that can execute them with the appropriate context. Use a ScopeContext and ScopeTypeChecker when calling lambda expressions.

    Hierarchy (View Summary)

    Index

    Constructors

    • Creates a new LambdaExpression with the given variable name and expression body. The variable name is the identifier used in the expression body to refer to the input value of the lambda function.

      Parameters

      • variableName: string

        The name of the variable used in the lambda expression.

      • expression: Expression

        The expression body of the lambda function.

      Returns LambdaExpression

    Properties

    syntax: string
    variableName: string
    expression: Expression
    compiled?: Function

    Methods

    • Get the original syntax string that was used to create this expression. This can be useful for debugging, logging, or error messages to provide context about where the expression came from.

      Returns string

      the original syntax string of the expression.

    • Get the name of the variable used in the lambda expression.

      Returns string

      The name of the variable.

    • What data keys are required for this expression to be evaluated? This information is used by the rule engine to determine the dependencies between expressions and rules, and to ensure that all necessary data is available before evaluating the expression.

      Returns Set<string>

      a set of data keys required for this expression to be evaluated.

    • What functions are invoked by this expression? This information can be used for optimization, caching, or to determine which function nodes in the graph are relevant for this expression.

      Returns Set<string>

      a set of function names invoked by this expression.

    • Get the return type of the lambda expression. This can be an atomic type or an object type, depending on the expression body.

      Parameters

      • Optionalchecker: TypeChecker

        optional type checker to use for determining the return type. This is needed for cases where the return type depends on variable types or function return types.

      Returns AtomicType | ObjectType

      The return type of the lambda expression.

    • Evaluate the expression in the given context to compute its value. The implementation of this method will depend on the specific type of expression and how it computes its value based on the data in the context.

      Parameters

      • context: WorkingContext

        the current working context containing data and constants.

      Returns any

      the computed value of the expression.