Coverage for /run/media/veganeco/water/status600.com/pypi/reptilian_climates/modules_series_2/ships/fields/gardens_pip/rich/_loop.py: 36%

1 from typing import Iterable, Tuple, TypeVar

2

3 T = TypeVar("T")

4

5

6 def loop_first(values: Iterable[T]) -> Iterable[Tuple[bool, T]]:

7 """Iterate and generate a tuple with a flag for first value."""

8 iter_values = iter(values)

9 try:

10 value = next(iter_values)

11 except StopIteration:

12 return

13 yield True, value

14 for value in iter_values:

15 yield False, value

16

17

18 def loop_last(values: Iterable[T]) -> Iterable[Tuple[bool, T]]:

19 """Iterate and generate a tuple with a flag for last value."""

20 iter_values = iter(values)

21 try:

22 previous_value = next(iter_values)

23 except StopIteration:

24 return

25 for value in iter_values:

26 yield False, previous_value

27 previous_value = value

28 yield True, previous_value

29

30

31 def loop_first_last(values: Iterable[T]) -> Iterable[Tuple[bool, bool, T]]:

32 """Iterate and generate a tuple with a flag for first and last value."""

33 iter_values = iter(values)

34 try:

35 previous_value = next(iter_values)

36 except StopIteration:

37 return

38 first = True

39 for value in iter_values:

40 yield first, False, previous_value

41 first = False

42 previous_value = value

43 yield first, True, previous_value