Skip to content

Instantly share code, notes, and snippets.

Created December 31, 2012 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/4416846 to your computer and use it in GitHub Desktop.
Save anonymous/4416846 to your computer and use it in GitHub Desktop.
Guard clause example
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