isOneOf<T> function

IValidator isOneOf<T>(
  1. Iterable<T> options, {
  2. String? message,
})

Checks whether the given value is one of the options values of type T

Implementation

IValidator isOneOf<T>(Iterable<T> options, {String? message}) {
  return Validator(
    (value) => Result(
      isValid: options.contains(value),
      expectation: Expectation(
        message: message ?? 'one of: ${prettifyValue(options)}',
        value: value,
        code: ExpectationCodes.valueMembershipMismatch,
        data: {'options': options.map((e) => e.toString()).toList()},
      ),
      value: value,
    ),
  );
}