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

1 from collections.abc import Callable, Iterable

2 from typing import TypeVar, overload

3

4 from .decorator import make_data_last

5 from .find import find

6

7 T = TypeVar('T')

8 U = TypeVar('U')

9

10

11@overload

12 def difference_with(

13 data: Iterable[T],

14 other: Iterable[U],

15 is_equal: Callable[[T, U], bool],

16 /,

17) -> Iterable[T]: ...

18

19

20@overload

21 def difference_with(

22 other: Iterable[U],

23 is_equal: Callable[[T, U], bool],

24 /,

25) -> Callable[[Iterable[T]], Iterable[T]]: ...

26

27

28@make_data_last

29 def difference_with(

30 data: Iterable[T],

31 other: Iterable[U],

32 is_equal: Callable[[T, U], bool],

33 /,

34) -> Iterable[T] | Callable[[Iterable[T]], Iterable[T]]:

35 other_ = list(other)

36 for x in data:

37 if (i := find(other_, lambda a, xx=x: is_equal(xx, a))) is not None:

38 other_.remove(i)

39 else:

40 yield x