Browse Source

functional.firstof API more flexible (accepts iterable or args).

backports/m1-live
Erik Stein 8 years ago
parent
commit
d1b69388eb
  1. 7
      utils/functional.py

7
utils/functional.py

@ -3,11 +3,16 @@ from __future__ import unicode_literals
# Erik Stein <code@classlibrary.net>, 2017 # Erik Stein <code@classlibrary.net>, 2017
def firstof(iterable, default=None): def firstof(*args, default=None):
""" """
Returns the first value which is neither empty nor 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: for value in iterable:
if value: if value:
return value return value

Loading…
Cancel
Save