Coverage for src/pymmails/helpers/iter_helper.py: 100%
15 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-04 01:15 +0200
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-04 01:15 +0200
1"""
2@file
3@brief Helpers with iterator
4"""
7def iterator_prev_next(iter):
8 """
9 iterator on a sequence and returns another iterator with
10 ``previous item, current item, next item``,
12 @param iter iterator
13 @return iterator
15 the previous item is ``None`` at the beginning of the sequence,
16 the next item is the same at the end of the sequence
17 """
18 prev, item, next = None, None, None
19 notempty = False
20 for current in iter:
21 notempty = True
22 prev = item
23 item = next
24 next = current
25 if item is not None:
26 yield prev, item, next
27 if notempty:
28 prev = item
29 item = next
30 next = None
31 yield prev, item, next