Why does Ior have only two generic types as parameters?
Isn't this inconsistent with the benefits of typed errors, since a "warning" can be different from an "error"?
Doesn't this make "exhaustive when" confusing for error handling?
Would it be considered bad practice if the following code were possible?
sealed interface UsernameError {
object TooShort : UsernameError
object TooLarge : UsernameError
}
sealed interface UsernameWarning {
object ShouldBeShorter : UsernameWarning
object WithDeprecatedChar : UsernameWarning
}
@JvmInline
value class Username private constructor(val value: String) {
companion object {
fun create(value: String): Ior<UsernameError,UsernameWarning, Username> {
return when {
value.length < 8 -> UsernameError.TooShort.leftIor()
value.length > 64 -> UsernameError.TooLarge.leftIor()
value.length > 20 -> Pair(UsernameWarning.ShouldBeShorter, Username(value)).bothIor()
value.contains('#') -> Pair(UsernameWarning.WithDeprecatedChar, Username(value)).bothIor()
else -> Username(value).rightIor()
}
}
}
}
I would like to understand the reason why the library does not allow this possibility.