Created
September 6, 2025 00:16
-
-
Save jordanorelli/df0274a95d9e5c432317766c3b6d145a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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