Skip to content

Instantly share code, notes, and snippets.

@hadilq
Last active January 10, 2021 23:20
Show Gist options
  • Save hadilq/05fee577c141689db19f3783564713c3 to your computer and use it in GitHub Desktop.
Save hadilq/05fee577c141689db19f3783564713c3 to your computer and use it in GitHub Desktop.
public class ValidationResultElseIfBuilder(
public val parent: ValidationResult
) {
public lateinit var result: Success
public inline fun InvalidEmailAddress(block: (errorMessage: String) -> Success): Unit {
if(parent is InvalidEmailAddress) {
result = block(parent.errorMessage)
}
}
public inline fun EmptySubject(block: (errorMessage: String) -> Success): Unit {
if(parent is EmptySubject) {
result = block(parent.errorMessage)
}
}
public inline fun EmptyBody(block: (errorMessage: String) -> Success): Unit {
if(parent is EmptyBody) {
result = block(parent.errorMessage)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment