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)
| 74 | |
| 75 | |
| 76 | def 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 | |
| 89 | def firstmethod(method, on_call=None): |