MCPcopy Create free account
hub / github.com/celery/celery / first

Function first

celery/utils/functional.py:76–86  ·  view source on GitHub ↗

Return the first element in ``it`` that ``predicate`` accepts. If ``predicate`` is None it will return the first item that's not :const:`None`.

(predicate, it)

Source from the content-addressed store, hash-verified

74
75
76def first(predicate, it):
77 """Return the first element in ``it`` that ``predicate`` accepts.
78
79 If ``predicate`` is None it will return the first item that's not
80 :const:`None`.
81 """
82 return next(
83 (v for v in evaluate_promises(it) if (
84 predicate(v) if predicate is not None else v is not None)),
85 None,
86 )
87
88
89def firstmethod(method, on_call=None):

Callers 5

test_firstFunction · 0.90
eitherMethod · 0.90
firstMethod · 0.85

Calls 2

evaluate_promisesFunction · 0.85
predicateFunction · 0.85