Created
November 7, 2017 21:18
-
-
Save sepulchered/ab22efb167dbbf0bdfe61d34d3842df8 to your computer and use it in GitHub Desktop.
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
import functools | |
def maybe(fn): | |
@functools.wraps(fn) | |
def wrapper(*args, **kwargs): | |
try: | |
return fn(*args, **kwargs) | |
except Exception: | |
return None | |
return wrapper | |
@maybe | |
def divide(num, den): | |
return num / den | |
def maybe_fn(default_val, fn, maybe_val): | |
if maybe_val is None: | |
return default_val | |
return fn(maybe_val) | |
def is_just(maybe_val): | |
return maybe_val is not None | |
def is_nothing(maybe_val): | |
return maybe_val is None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment