FormLab.kt
- 1sealed interface Check {
- 2 data class Ok(val email: String) : Check
- 3 data class Reason(val message: String) : Check
- 4}
- 5
- 6fun checkEmail(raw: String): Check {
- 7 val email = raw.trim()
- 8 if (!email.contains("@")) return Check.Reason("Need a full address")
- 9 return Check.Ok(email)
- 10}
A form that keeps null visible
An email field starts empty. Empty and null are not the same mistake.
- The field state is String, starting at "". Null is reserved for a missing record, not for an untouched box.
- Validation returns a sealed result: Ok or Reason. The button reads that result.
- A platform type from an old Java helper is normalized at the edge with orEmpty().