Skip to content

Support for Lambda Functions and Custom Callables #38

Open
@quaaantumdev

Description

@quaaantumdev

Currently, function calls within expressions rely on Function.apply, which offers no mechanism for handling parameter mismatches gracefully. This can lead to unhelpful runtime errors for users of the library.

We propose introducing a Callable abstract class. This would serve as a formal interface for function-like objects within the expression engine. While this is a prerequisite for supporting lambdas, it's a valuable addition on its own. It empowers users to create their own callable objects that can validate arguments and provide much more descriptive exceptions if, for instance, the wrong number of parameters is supplied.

Building on this Callable infrastructure, we can introduce support for lambda functions. By parsing the familiar arrow syntax (param) => expression, we can dramatically enhance the power of the library. This simple addition unlocks the ability to perform common collection operations like filtering, mapping, and reducing directly within an expression string.

For example: [1, 9, 2].where((e) => e > 2)

When evaluated, the lambda would have access to the parameters passed to it (like e) as well as any variables available in the context where it was defined, just as a developer would expect from a lexical closure.

This issue is solved by #39

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions