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

Allow to use operator tokens as functions #577

Closed

Conversation

ckganesan
Copy link
Contributor

@ckganesan ckganesan commented Feb 23, 2024

This PR enables the usage of operator tokens as functions. #572

@antonmedv
Copy link
Member

Lets just allow to use "endsWith"
"startsWith"
"contains"
"matches" words as method names?

@ckganesan
Copy link
Contributor Author

Lets just allow to use "endsWith" "startsWith" "contains" "matches" words as method names?

I have made the necessary updates based on your feedback.

@Q16G
Copy link

Q16G commented Feb 27, 2024

This function is very important for my code, could you please add this function to the latest version with a tag, so that I can add it to the code

@antonmedv
Copy link
Member

Let's try to implement this feature without adding additional options. I will try to do it.

@ckganesan
Copy link
Contributor Author

ckganesan commented Feb 27, 2024

Let's try to implement this feature without adding additional options. I will try to do it.

I have removed option functionality from configuration as per your feedback

parser/parser_test.go Outdated Show resolved Hide resolved
parser/parser_test.go Outdated Show resolved Hide resolved
@antonmedv
Copy link
Member

Awesome work!

@antonmedv
Copy link
Member

I actually not understand what original issues is was about: #568

Is to be able to use reuse operator names as functions:

	options := []expr.Option{
		expr.Function(
			"contains",
			func(params ...any) (any, error) {
				return false, nil
			},
			new(func() bool),
		),
	}

	program, err := expr.Compile(`contains()`, options...)

I think this is a bad practice and not should be allowed. Also I think it's bad decision to allow to use some operators as functions =/

Let's not processed this this PR @ckganesan?

@Q16G
Copy link

Q16G commented Mar 3, 2024

operator becomes a function to increase the extensibility, convenient for users to customize or extend. Consider a scenario where the user needs to pass in multiple arguments to the contains function, and the original operator is not satisfied, we can extend it to contain from an operator to a function

@antonmedv
Copy link
Member

Consider a scenario where the user needs to pass in multiple arguments to the contains function

Can you show some examples?

@Q16G
Copy link

Q16G commented Mar 7, 2024

Because I think this allows the user to customize a higher degree, the experience will be better

@antonmedv antonmedv closed this Mar 7, 2024
@Q16G
Copy link

Q16G commented Mar 7, 2024

Will this operation be allowed

@antonmedv
Copy link
Member

No. For now, not. I don't see a use case. And adding such feature complicates parser and type checker.

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 this pull request may close these issues.

3 participants