Coverage for src/remedapy/unique.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 unique(it: Iterable[T], /) -> Iterable[T]: ...

11

12

13@overload

14 def unique() -> Callable[[Iterable[T]], Iterable[T]]: ...

15

16

17@make_data_last

18 def unique(it: Iterable[T], /) -> Iterable[T]:

19 seen = set[T]()

20 for x in it:

21 if x not in seen:

22 seen.add(x)

23 yield x