From d1b69388eb9febd433f26d6895fe99183d0d94c2 Mon Sep 17 00:00:00 2001 From: Erik Stein Date: Mon, 31 Jul 2017 16:54:23 +0200 Subject: [PATCH] functional.firstof API more flexible (accepts iterable or args). --- utils/functional.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/utils/functional.py b/utils/functional.py index d18fa93..2c3cdaa 100644 --- a/utils/functional.py +++ b/utils/functional.py @@ -3,11 +3,16 @@ from __future__ import unicode_literals # Erik Stein , 2017 -def firstof(iterable, default=None): +def firstof(*args, default=None): """ Returns the first value which is neither empty nor None. """ + if len(args) == 1: + iterable = args[0] + else: + iterable = args + for value in iterable: if value: return value