Skip to content

Instantly share code, notes, and snippets.

@hadilq
Created January 10, 2021 23:12
Show Gist options
  • Save hadilq/79ea2cbc789e6132af6e764b821b046b to your computer and use it in GitHub Desktop.
Save hadilq/79ea2cbc789e6132af6e764b821b046b to your computer and use it in GitHub Desktop.
Complete doWork method for more complex scenario
fun doWork(): Result<Unit> {
return input() into
::parse elseIf
{
return Failure("Cannot parse email")
} into
::validate elseIf
{
InvalidEmailAddress { message -> return Failure(message) }
EmptySubject(::fixEmptySubject)
EmptyBody { message -> return Failure(message) }
} into
::send elseIf
{
IOFailure { error -> return Failure(error.message ?: "") }
Timeout { error -> return Failure(error.message ?: "") }
UnAuthorized { validatedEmail, _ ->
validatedEmail into
::authorizeAndSend elseIf
{
return Failure(it)
} into
{ SendSuccess(validatedEmail.email) }
}
} into
{ Success(Unit) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment