Coverage for src/remedapy/splice.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 splice(items: Iterable[T], start: int, delete_count: int, replacement: Iterable[T], /) -> Iterable[T]: ...

11

12

13@overload

14 def splice(start: int, delete_count: int, replacement: Iterable[T], /) -> Callable[[Iterable[T]], Iterable[T]]: ...

15

16

17@make_data_last

18 def splice(items: Iterable[T], start: int, delete_count: int, replacement: Iterable[T], /) -> Iterable[T]:

19 iterable = iter(items)

20 i = 0

21 while i < start:

22 yield next(iterable)

23 i += 1

24 yield from replacement

25 for _ in range(delete_count):

26 next(iterable)

27 yield from iterable