parlot icon indicating copy to clipboard operation
parlot copied to clipboard

Create `LeftAssociative` overload with more friendly factory

Open gumbarros opened this issue 1 year ago • 1 comments
trafficstars

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);
});

gumbarros avatar Jun 02 '24 21:06 gumbarros