Created
January 10, 2021 23:12
-
-
Save hadilq/79ea2cbc789e6132af6e764b821b046b to your computer and use it in GitHub Desktop.
Complete doWork method for more complex scenario
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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