Coverage for src / remedapy / difference_with.py: 100%
13 statements
« prev ^ index » next coverage.py v7.13.2, created at 2026-02-02 10:52 +0100
« prev ^ index » next coverage.py v7.13.2, created at 2026-02-02 10:52 +0100
1from collections.abc import Callable, Iterable
2from typing import TypeVar, overload
4from .decorator import make_data_last
5from .find import find
7T = TypeVar('T')
8U = TypeVar('U')
11@overload
12def difference_with(
13 data: Iterable[T],
14 other: Iterable[U],
15 is_equal: Callable[[T, U], bool],
16 /,
17) -> Iterable[T]: ...
20@overload
21def difference_with(
22 other: Iterable[U],
23 is_equal: Callable[[T, U], bool],
24 /,
25) -> Callable[[Iterable[T]], Iterable[T]]: ...
28@make_data_last
29def 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