Skip to content

Instantly share code, notes, and snippets.

@zackmdavis
Created March 14, 2018 22:09
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 zackmdavis/65d5d8d8c4fd4638e2e20eab1615a1d2 to your computer and use it in GitHub Desktop.
Save zackmdavis/65d5d8d8c4fd4638e2e20eab1615a1d2 to your computer and use it in GitHub Desktop.
from typing import Optional, TypeVar
T = TypeVar('T')
U = TypeVar('U')
def option_map(arg: Optional[T], fn: Callable[[T], U]) -> Optional[U]:
if arg is not None:
return fn(arg)
else:
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment