From e7b5601a88548c0bcadde08cce14dc94e5a10d51 Mon Sep 17 00:00:00 2001 From: chriskiehl Date: Thu, 7 Jan 2016 21:13:15 -0500 Subject: [PATCH] functional tools for gooey --- gooey/gui/util/casting.py | 15 +++++++++++++++ gooey/gui/util/functional.py | 10 ++++++++++ 2 files changed, 25 insertions(+) create mode 100644 gooey/gui/util/casting.py create mode 100644 gooey/gui/util/functional.py diff --git a/gooey/gui/util/casting.py b/gooey/gui/util/casting.py new file mode 100644 index 0000000..8e90544 --- /dev/null +++ b/gooey/gui/util/casting.py @@ -0,0 +1,15 @@ + + +def safe_int(n): + return _safe_cast(int, n) + +def safe_float(n): + return _safe_cast(float, n) + + +def _safe_cast(_type, val): + try: + return _type(val) + except ValueError: + return None + diff --git a/gooey/gui/util/functional.py b/gooey/gui/util/functional.py new file mode 100644 index 0000000..8d0c8d4 --- /dev/null +++ b/gooey/gui/util/functional.py @@ -0,0 +1,10 @@ +''' +Simple monad-ish bindings +''' + + +def unit(val): + return val + +def bind(val, f): + return f(val) if val else None