Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add operator “overloading” #30

Closed
Tracked by #49
cshaa opened this issue May 6, 2021 · 1 comment
Closed
Tracked by #49

Add operator “overloading” #30

cshaa opened this issue May 6, 2021 · 1 comment
Labels
enhancement New feature or request implemented This feature is implemented in `develop` and ready for testing
Milestone

Comments

@cshaa
Copy link
Owner

cshaa commented May 6, 2021

The options object should allow for methods like customAdd and customGreaterThan that would override the default action of these operators.

@cshaa cshaa added enhancement New feature or request good first issue Good for newcomers labels May 6, 2021
@cshaa cshaa added this to the v3 milestone May 6, 2021
@cshaa cshaa added the implemented This feature is implemented in `develop` and ready for testing label Jun 17, 2021
@cshaa
Copy link
Owner Author

cshaa commented Jun 17, 2021

In the actual implementation, I went with this API:

interface Options {
  // ...
  
  operators: {
    '+': (a, b) => any,
    '-': (a, b) => any,
    // ...
  }
}

The minus operator overload is used for both the binary and the unary operator:

  • -a will result in operators['-'](a)
  • a - b will result in operators['-'](a, b).

The modulo operator can be overloaded using operators['mod'].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request implemented This feature is implemented in `develop` and ready for testing
Projects
None yet
Development

No branches or pull requests

1 participant