Created
December 31, 2012 02:09
-
-
Save anonymous/4416846 to your computer and use it in GitHub Desktop.
Guard clause example
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
email_obj = process_email(email_string) | |
if email_obj.has_data: | |
if email_obj.has_images or email_obj.has_unsupported_images: | |
process_images(email_obj.images) | |
else: | |
process_text(email_obj.text) | |
else: | |
raise InvalidEmail | |
# with guard clause | |
email_obj = process_email(email_string) | |
if not email_obj.has_data: | |
raise InvalidEmail | |
if email_obj.has_images or email_obj.has_unsupported_images: | |
process_images(email_obj.images) | |
else: | |
process_text(email_obj.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment