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

Create LeftAssociative overload with more friendly factory #127

Open
gumbarros opened this issue Jun 2, 2024 · 1 comment · May be fixed by #128
Open

Create LeftAssociative overload with more friendly factory #127

gumbarros opened this issue Jun 2, 2024 · 1 comment · May be fixed by #128

Comments

@gumbarros
Copy link
Contributor

Is possible to create a more friendly overload?

Actual:

var equal = Terms.Text("=").Or(Terms.Text("=="));
var notEqual = Terms.Text("<>").Or(Terms.Text("!="));

var equality = relational.LeftAssociative(
    (equal, static (a, b) => new BinaryExpression(BinaryExpressionType.Equal, a, b)),
    (notEqual, static (a, b) => new BinaryExpression(BinaryExpressionType.NotEqual, a, b))
);

Suggestion:

var equal = Terms.Text("=").Or(Terms.Text("==")).Then(_=>BinaryExpressionType.Equal);
var notEqual = Terms.Text("<>").Or(Terms.Text("!=")).Then(_=>BinaryExpressionType.NotEqual);

var equality = relational.LeftAssociative([equal, notEqual], (a,b, operation)=>{
return new BinaryExpression(operation, a, b);
});
@sebastienros
Copy link
Owner

It's something that could be added, looks nice for your case. Feel free to submit a PR with a test.

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

Successfully merging a pull request may close this issue.

2 participants