Iterate and generate a tuple with a flag for first and last value.
(values: Iterable[T])
| 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 |
no outgoing calls