Skip to content

Add In() and IsNotIn() to Comparable, String, and Enum validators. #57

@DreadLordMikey

Description

@DreadLordMikey

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions