Skip to content

Instantly share code, notes, and snippets.

@hadilq
Created January 10, 2021 23:10
Show Gist options
  • Save hadilq/8f1ed8a01a2fdd9221e92666343407dd to your computer and use it in GitHub Desktop.
Save hadilq/8f1ed8a01a2fdd9221e92666343407dd to your computer and use it in GitHub Desktop.
Complete doWork method
fun doWork(): Result<Unit> {
return input() into
::parse elseIf
{
return Failure("Cannot parse email")
} into
::validate elseIf
{
InvalidEmailAddress { message -> return Failure(message) }
EmptySubject { message -> return Failure(message) }
EmptyBody { message -> return Failure(message) }
} into
::send elseIf
{
IOFailure { error -> return Failure(error.message ?: "") }
Timeout { error -> return Failure(error.message ?: "") }
UnAuthorized { error -> return Failure(error.message ?: "") }
} into
{ Success(Unit) }
}
fun parse(input: String): Result<Email> = ...
fun validate(input: Success<Email>): ValidationResult = ...
fun send(input: ValidateSuccess): SendResult = ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment