MCPcopy Create free account
hub / github.com/celery/celery / lookahead

Function lookahead

celery/utils/functional.py:171–181  ·  view source on GitHub ↗

Yield pairs of (current, next) items in `it`. `next` is None if `current` is the last item. Example: >>> list(lookahead(x for x in range(6))) [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, None)]

(it)

Source from the content-addressed store, hash-verified

169
170
171def lookahead(it):
172 """Yield pairs of (current, next) items in `it`.
173
174 `next` is None if `current` is the last item.
175 Example:
176 >>> list(lookahead(x for x in range(6)))
177 [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, None)]
178 """
179 a, b = tee(it)
180 next(b, None)
181 return zip_longest(a, b)
182
183
184def regen(it):

Callers 1

test_lookaheadFunction · 0.90

Calls

no outgoing calls

Tested by 1

test_lookaheadFunction · 0.72