Skip to content

Instantly share code, notes, and snippets.

@lucapiccinelli
Last active January 3, 2021 08:06
Show Gist options
  • Save lucapiccinelli/b094810ea1014fd81634059236d2b1ee to your computer and use it in GitHub Desktop.
Save lucapiccinelli/b094810ea1014fd81634059236d2b1ee to your computer and use it in GitHub Desktop.
sealed class Email(val value: String){
data class Verified(private val email: Unverified): Email(email.value)
class Unverified private constructor(value: String): Email(value){
companion object{
fun of(value: String): Result<Email.Unverified> = valikate {
validate(Email.Unverified(value)){
validate(Email.Unverified::value).isEmail()
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment