Title: Provide common replacement utils / functions many projects will need · Issue #65 · python-trio/unasync · GitHub
Open Graph Title: Provide common replacement utils / functions many projects will need · Issue #65 · python-trio/unasync
X Title: Provide common replacement utils / functions many projects will need · Issue #65 · python-trio/unasync
Description: Some utility functions I was thinking about: def azip(*iterables): # Convert any iterables and async iterables into a zipped async iterable iterators = [aiter(x) for x in iterables] async def generator(): while True: try: yield tuple([aw...
Open Graph Description: Some utility functions I was thinking about: def azip(*iterables): # Convert any iterables and async iterables into a zipped async iterable iterators = [aiter(x) for x in iterables] async def gener...
X Description: Some utility functions I was thinking about: def azip(*iterables): # Convert any iterables and async iterables into a zipped async iterable iterators = [aiter(x) for x in iterables] async def gener...
Opengraph URL: https://github.com/python-trio/unasync/issues/65
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Provide common replacement utils / functions many projects will need","articleBody":"Some utility functions I was thinking about:\r\n\r\n```python\r\ndef azip(*iterables): # Convert any iterables and async iterables into a zipped async iterable\r\n iterators = [aiter(x) for x in iterables]\r\n\r\n async def generator():\r\n while True:\r\n try:\r\n yield tuple([await x.__anext__() for x in iterators])\r\n except StopAsyncIteration:\r\n break\r\n\r\n return generator().__aiter__()\r\n\r\ndef aiter(x): # Convert any iterable or async iterable into an async iterator\r\n if hasattr(x, \"__aiter__\"):\r\n return x.__aiter__()\r\n elif hasattr(x, \"__anext__\"):\r\n return x\r\n\r\n async def aiter_wrapper():\r\n for item in x:\r\n yield item\r\n\r\n return aiter_wrapper().__aiter__()\r\n\r\nasync def anext(i): # Advance an async iterator, good for mapping to `next()`\r\n return await i.__anext__()\r\n\r\n\r\nasync def await_or_return(x): # Maps to 'return_()'?\r\n if iscoroutine(x):\r\n return await x\r\n return x\r\n\r\n\r\n# All of the sync variations of the above functions\r\nnext = next\r\niter = iter\r\nzip = zip\r\ndef return_(x):\r\n return x\r\n```\r\n\r\nCould also have `azip_longest` -\u003e `zip_longest`, etc.\r\n\r\nAll of the `async` functions could be available only on Python 3.6+ so this could be used on projects that support 3.5 or less.\r\n\r\nCould also provide type hints that are effected by `unasync` properly as well.\r\n\r\n```python\r\nAsyncOrSyncIterable[X] = Union[AsyncIterable[X], Iterable[X]]\r\nSyncIterable[X] = Iterable[X]\r\n```\r\n\r\nThis should probably be a separate project to unasync as unasync is primarily a build tool, raising it here because it'd make sense for the tool to live under `python-trio`, maybe `unasync-utils`?","author":{"url":"https://github.com/sethmlarson","@type":"Person","name":"sethmlarson"},"datePublished":"2020-05-07T14:19:27.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/65/unasync/issues/65"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:58cc9f3b-df5c-cf2d-6121-c8c4291174d8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AFE0:3FD06A:F08B9:143E38:696F1429 |
| html-safe-nonce | 73b5950f8ce796c0be6abc03372104bbb23d837b8dff8aabe72901956d8df4b5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRkUwOjNGRDA2QTpGMDhCOToxNDNFMzg6Njk2RjE0MjkiLCJ2aXNpdG9yX2lkIjoiNDYwMjIyMzQyMDI5MDM1OTMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 09c66e09b9ed0be7729abd4308cd4a0c6c6e40a34548962087e7991a61b4405e |
| hovercard-subject-tag | issue:614095567 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python-trio/unasync/65/issue_layout |
| twitter:image | https://opengraph.githubassets.com/15069801884f19f347b055282e30194f77a25c380047b8f45d0255c67fd9bebc/python-trio/unasync/issues/65 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/15069801884f19f347b055282e30194f77a25c380047b8f45d0255c67fd9bebc/python-trio/unasync/issues/65 |
| og:image:alt | Some utility functions I was thinking about: def azip(*iterables): # Convert any iterables and async iterables into a zipped async iterable iterators = [aiter(x) for x in iterables] async def gener... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sethmlarson |
| hostname | github.com |
| expected-hostname | github.com |
| None | b278ad162d35332b6de714dfb005de04386c4d92df6475522bef910f491a35ee |
| turbo-cache-control | no-preview |
| go-import | github.com/python-trio/unasync git https://github.com/python-trio/unasync.git |
| octolytics-dimension-user_id | 26335827 |
| octolytics-dimension-user_login | python-trio |
| octolytics-dimension-repository_id | 154537846 |
| octolytics-dimension-repository_nwo | python-trio/unasync |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 154537846 |
| octolytics-dimension-repository_network_root_nwo | python-trio/unasync |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 39aed5006635ab6f45e6b77d23e73b08a00272a3 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width