Skip to content

Instantly share code, notes, and snippets.

@jordanorelli
Created September 6, 2025 00:16
Show Gist options
  • Select an option

  • Save jordanorelli/df0274a95d9e5c432317766c3b6d145a to your computer and use it in GitHub Desktop.

Select an option

Save jordanorelli/df0274a95d9e5c432317766c3b6d145a to your computer and use it in GitHub Desktop.
def cool():
n = 0
while True:
delta = yield n
if delta is not None:
n += delta
else:
n += 1
# Used like an iterator
it = cool()
print(it.send(None))
print(it.send(None))
print(it.send(None))
print(it.send(None))
print(it.send(None))
# You can pass a delta in to say how much you wan to increment
coro = cool()
print(coro.send(None))
print(coro.send(2))
print(coro.send(1))
print(coro.send(5))
print(coro.send(1))
0
1
2
3
4
--------------------------------------------------------------------------------
0
2
3
8
9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment