asResult method
Converts this validation result to a Result type.
Valid becomes Ok with the value, Invalid becomes Err with the error set. Use this to integrate validated values with Result-based code paths, or to leverage Result utilities for further processing.
The error set can then be handled like any other Result error using methods like Result.mapErr, Result.unwrapOr, etc.
Example:
final validation = check(input, (i) => i.isNotEmpty, error: 'Required');
final result = validation.asResult();
// Now you can use Result methods
final value = result.unwrapOr('default');
final mapped = result.mapErr((errors) => errors.join(', '));
Implementation
Result<T, Set<String>> asResult() => switch (this) {
Invalid<T>(:final errors) => .err(errors),
Valid<T>(:final value) => .ok(value),
};