From 602dda5c50b5357a565243757a5a154ff2eff145 Mon Sep 17 00:00:00 2001 From: Erik Stein Date: Thu, 6 Jul 2017 14:18:42 +0200 Subject: [PATCH] Added functional utils. --- utils/functional.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 utils/functional.py diff --git a/utils/functional.py b/utils/functional.py new file mode 100644 index 0000000..d18fa93 --- /dev/null +++ b/utils/functional.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals +# Erik Stein , 2017 + + +def firstof(iterable, default=None): + """ + Returns the first value which is neither empty nor None. + + """ + for value in iterable: + if value: + return value + return default