Skip to content

Instantly share code, notes, and snippets.

@dwickstrom
Last active October 11, 2016 11:50
Show Gist options
  • Save dwickstrom/bca2a62e1bc2bb6860dda42361cbdf0c to your computer and use it in GitHub Desktop.
Save dwickstrom/bca2a62e1bc2bb6860dda42361cbdf0c to your computer and use it in GitHub Desktop.
@curry
def safe_cast(to_type, value):
try:
return Just.of(to_type(value))
except:
return Nothing
to_float = safe_cast(float)
to_int = safe_cast(int)
to_str = safe_cast(str)
to_dict = safe_cast(dict)
to_list = safe_cast(list)
to_set = safe_cast(set)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment