Skip to content

Instantly share code, notes, and snippets.

@mithrandi
Created September 13, 2017 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mithrandi/c69f77e9724f53fd5e3bdc65c918bbd5 to your computer and use it in GitHub Desktop.
Save mithrandi/c69f77e9724f53fd5e3bdc65c918bbd5 to your computer and use it in GitHub Desktop.
maybe
def maybe(f, v, default=None):
"""
Return C{f(v)} if C{v} is not C{None}, otherwise return C{default}.
"""
if v is None:
return default
return f(v)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment