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 In() and IsNotIn() to Comparable, String, and Enum validators. #57

Open
DreadLordMikey opened this issue Jun 1, 2022 · 0 comments

Comments

@DreadLordMikey
Copy link

DreadLordMikey commented Jun 1, 2022

In(params T[])

This type of validator would accept a sequence of values (the sequence). The implementation would scan the sequence and throw an exception if any element in the sequence evaluates to the value represented by the validator.

NotIn(params T[])

This type of validator would accept a sequence of values (the sequence). The implementation would scan the sequence and throw an exception if no element in the sequence evaluates to the value represented by the validator.

Justification:

This eliminates the need for verbose checks such as x == 1 || x == 3 || x == 17 || x == 21 and reduces them to x.In(1, 3, 17, 21), while x.NotIn(1, 3, 17, 21) is the natural reduction of x != 1 && x != 3 && x != 17 && x != 21.

This type of validation is appropriate for all comparable types (string, and all the numeric data types) and all Enum types.

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