MCPcopy
hub / github.com/Textualize/rich / loop_first_last

Function loop_first_last

rich/_loop.py:31–43  ·  view source on GitHub ↗

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

(values: Iterable[T])

Source from the content-addressed store, hash-verified

29
30
31def 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

Callers 4

test_loop_first_lastFunction · 0.90
_iter_syntax_linesFunction · 0.85
_get_cellsMethod · 0.85
_renderMethod · 0.85

Calls

no outgoing calls

Tested by 1

test_loop_first_lastFunction · 0.72