|
@@ -9,7 +9,6 @@
|
|
|
from __future__ import absolute_import
|
|
|
from __future__ import with_statement
|
|
|
|
|
|
-import operator
|
|
|
import threading
|
|
|
|
|
|
from functools import partial, wraps
|
|
@@ -17,12 +16,11 @@ from itertools import islice
|
|
|
|
|
|
from kombu.utils import cached_property
|
|
|
from kombu.utils.functional import promise, maybe_promise
|
|
|
-from kombu.utils.compat import OrderedDict
|
|
|
+from kombu.utils.compat import OrderedDict, next
|
|
|
|
|
|
from .compat import UserDict, UserList
|
|
|
|
|
|
KEYWORD_MARK = object()
|
|
|
-is_not_None = partial(operator.is_not, None)
|
|
|
|
|
|
|
|
|
class LRUCache(UserDict):
|
|
@@ -173,13 +171,17 @@ def noop(*args, **kwargs):
|
|
|
pass
|
|
|
|
|
|
|
|
|
-def first(predicate, iterable):
|
|
|
+def first(predicate, it):
|
|
|
"""Returns the first element in `iterable` that `predicate` returns a
|
|
|
- :const:`True` value for."""
|
|
|
- predicate = predicate or is_not_None
|
|
|
- for item in iterable:
|
|
|
- if predicate(item):
|
|
|
- return item
|
|
|
+ :const:`True` value for.
|
|
|
+
|
|
|
+ If `predicate` is None it will return the first item that is not None.
|
|
|
+
|
|
|
+ """
|
|
|
+ return next(
|
|
|
+ (v for v in it if (predicate(v) if predicate else v is not None)),
|
|
|
+ None,
|
|
|
+ )
|
|
|
|
|
|
|
|
|
def firstmethod(method):
|