Coverage for src/remedapy/find.py: 100%

1 from collections.abc import Callable, Iterable

2 from typing import TypeVar, overload

3

4 from .decorator import make_data_last

5

6 T = TypeVar('T')

7

8

9@overload

10 def find(data: Iterable[T], predicate: Callable[[T], bool], /) -> T | None: ...

11

12

13@overload

14 def find(predicate: Callable[[T], bool], /) -> Callable[[Iterable[T]], T | None]: ...

15

16

17@make_data_last

18 def find(first: Iterable[T], predicate: Callable[[T], bool], /):

19 for item in first:

20 if predicate(item):

21 return item

22 return None