{"id":31387,"date":"2021-01-20T16:35:03","date_gmt":"2021-01-20T21:35:03","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=31387"},"modified":"2021-02-19T15:55:44","modified_gmt":"2021-02-19T20:55:44","slug":"swift-asyncsequence","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2021\/01\/20\/swift-asyncsequence\/","title":{"rendered":"Swift AsyncSequence"},"content":{"rendered":"<p><a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0298-asyncsequence.md\">SE-0298<\/a> (via <a href=\"https:\/\/twitter.com\/Catfish_Man\/status\/1351676624236761090\">David Smith<\/a>, <a href=\"https:\/\/forums.swift.org\/t\/se-0298-async-await-sequences\/43786\">forum<\/a>):<\/p>\n<blockquote cite=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0298-asyncsequence.md\">\n<p>Swift&rsquo;s <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0296-async-await.md\">async\/await<\/a> feature provides an intuitive, built-in way to write and use functions that return a single value at some future point in time. We propose building on top of this feature to create an intuitive, built-in way to write and use functions that return many values over time.<\/p>\n<p>This proposal is composed of the following pieces:<\/p>\n<ol>\n<li>A standard library definition of a protocol that represents an asynchronous sequence of values<\/li>\n<li>Compiler support to use <code>for...in<\/code> syntax on an asynchronous sequence of values<\/li>\n<li>A standard library implementation of commonly needed functions that operate on an asynchronous sequence of values<\/li>\n<\/ol>\n<\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2020\/12\/07\/swift-proposal-for-async-await\/\">Swift Proposal for async\/await<\/a><\/li>\n<\/ul>\n\n<p id=\"swift-asyncsequence-update-2021-02-19\">Update (2021-02-19): <a href=\"https:\/\/forums.swift.org\/t\/follow-up-on-asyncsequence-and-parity-with-sequence-based-apis\/44893\/\">Philippe Hausler<\/a>:<\/p>\n<blockquote cite=\"https:\/\/forums.swift.org\/t\/follow-up-on-asyncsequence-and-parity-with-sequence-based-apis\/44893\/\">\n<p>To facilitate the collecting of values and moving from the asynchronous world into the synchronous world we should add an extension on <code>AsyncSequence<\/code> of <code>collect<\/code> to gather up all the values asynchronously and produce an array of those values. This of course means that the function must follow the effects entailed with said asynchronous iteration; that means that when an <code>AsyncSequence<\/code> that throws is collected it will throw and when it does not throw of course that collecting process should not throw. This means that the act should be rethrows according to the conformance of the type it is called upon. Furthermore collecting all values must also be in it of itself asynchronous.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>SE-0298 (via David Smith, forum): Swift&rsquo;s async\/await feature provides an intuitive, built-in way to write and use functions that return a single value at some future point in time. We propose building on top of this feature to create an intuitive, built-in way to write and use functions that return many values over time. This [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2021-01-20T21:35:05Z","apple_news_api_id":"4de057db-d09e-4384-b3fe-f21fd2d8a6fb","apple_news_api_modified_at":"2021-02-19T20:55:47Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAA==","apple_news_api_share_url":"https:\/\/apple.news\/ATeBX29CeQ4Sz_vIf0tim-w","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[1813,46,71,901],"class_list":["post-31387","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-combine-framework","tag-languagedesign","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/31387","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=31387"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/31387\/revisions"}],"predecessor-version":[{"id":31685,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/31387\/revisions\/31685"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=31387"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=31387"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=31387"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}