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

Missing features (or too many restrictions) for general purpose expression evaluator #114

Open
cr3ativ3 opened this issue Apr 13, 2021 · 0 comments

Comments

@cr3ativ3
Copy link

cr3ativ3 commented Apr 13, 2021

When I saw this library and that it supports custom operators and functions I very much wanted to include it in my project as an expression evaluator, but sadly could because it is very (unnecessarily) limited for only math. Mainly because:

  • expression must be provided in builder constructor (unnecessarily) when it is only neede at build() call. You might want to reuse the same custom Op or Func configuration (same builder) on multiple expressions, now you have to re-create it for each expression
  • arguments can only be doubles (this is bad even for math, as BigDecimal would have infinite precision)
  • evaluates only to double (again, BigDecimal would be more precise even if you only want to support Math, could have "evaluateDoube(), evaluateBool(), or have generics similar to Optional, etc.),
  • cannot configure exclude native functions or operators if you don't want to support them
  • APIs also could be improved. for example all operations have either 1 or 2 arguments, so instead of double...varargs it could be Operator.appy(Double left, Double right) with "left" being null for things like negative number, and "right" be null for factors ie. 4!. Also instead of custom Operator class it could actually use Java's default BiFunction, and similar improvements
  • many many many unnecessary validations:
    • only certain symbols can be used for operators, why forbid using any "string" as operator? ie. "X div Y"
    • variables must have a specific format (start/end/etc), why can't I have all my variables start with % ?
    • variable and function names must be different (here a custom prefix functionality would help)
    • and many many more..

My use-case was / I though that I will be able to create with this library something to evaluate custom expressions like "$distance(%d1, %d2) >= 10 && $size(%myarray) < %var3" and I could create custom Functions for $Distance(Number, Number) and $Size(Collection), Operators for "<", ">=" (less, more or equals returning boolean), "&&" (boolean comparator returning boolean) that in the end could evaluate to Boolean. Ability to disable implicit functions like sin, cos, etc. would be a bonus.

However it was impossible, because of validations and limitation to "only use doubles". The saddest part is that the main backbone code of this library could do so much more (everything I wanted to do above). Perhaps I will fork it or just copy the useful parts to my code and refactor to support what I need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant