Coverage for src/remedapy/find_index.py: 90%

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_index(data: Iterable[T], predicate: Callable[[T], bool], /) -> int: ...

11

12

13@overload

14 def find_index(predicate: Callable[[T], bool], /) -> Callable[[Iterable[T]], int]: ...

15

16

17@make_data_last

18 def find_index(data: Iterable[T], predicate: Callable[[T], bool], /):

19 for i, item in enumerate(data):

20 if predicate(item):

21 return i

22 return -1