{"id":35398,"date":"2022-03-28T16:35:53","date_gmt":"2022-03-28T20:35:53","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=35398"},"modified":"2024-12-10T11:43:27","modified_gmt":"2024-12-10T16:43:27","slug":"swift-async-algorithms-package","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2022\/03\/28\/swift-async-algorithms-package\/","title":{"rendered":"Swift &ldquo;Async Algorithms&rdquo; Package"},"content":{"rendered":"<p><a href=\"https:\/\/www.swift.org\/blog\/swift-async-algorithms\/\">Tony Parker<\/a> (<a href=\"https:\/\/twitter.com\/SwiftLang\/status\/1507425192418574337\">tweet<\/a>):<\/p>\n<blockquote cite=\"https:\/\/www.swift.org\/blog\/swift-async-algorithms\/\"><p>AsyncAlgorithms is a package for algorithms that work with <em>values over time<\/em>. That includes those primarily about <em>time<\/em>, like <code>debounce<\/code> and <code>throttle<\/code>, but also algorithms about <em>order<\/em> like <code>combineLatest<\/code> and <code>merge<\/code>. Operations that work with multiple inputs (like <code>zip<\/code> does on <code>Sequence<\/code>) can be surprisingly complex to implement, with subtle behaviors and many edge cases to consider. A shared package can get these details correct, with extensive testing and documentation, for the benefit of all Swift apps.<\/p><p>[&#8230;]<\/p><p>We believe an open source package will provide a great home for these APIs. A package gives developers flexibility in deploying across both platforms and OS versions. Development and API design will take place on <a href=\"https:\/\/github.com\/apple\/swift-async-algorithms\">GitHub<\/a> and the <a href=\"https:\/\/forums.swift.org\/c\/related-projects\/swift-async-algorithms\/86\">Swift Forums<\/a>.<\/p><p>[&#8230;]<\/p><p>Combine&rsquo;s API is based on the <code>Publisher<\/code> and <code>Subscriber<\/code> interfaces, with <em>operators<\/em> to connect between them. Its design focuses on providing a way to declaratively specify a chain of these operators, transforming data as it moves from one end to the other. This requires thinking differently about intermediate state. Sometimes this leads to call sites that are more complex than one might expect &#x2013; especially when working with single values, errors, or data that needs to be shared. <code>async\/await<\/code>&rsquo;s <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0304-structured-concurrency.md\">Structured Concurrency<\/a> provides us with a new way to express this kind of logic. We can now write asynchronous code that is split into smaller pieces and reads from top-to-bottom instead of as a series of chained transforms.<\/p><\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/DLX\/status\/1507669248100995075\">robb<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/DLX\/status\/1507669248100995075\">\n<p>This reads very much like a eulogy to Combine<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/caseyliss\/status\/1507828215338962951\">Casey Liss<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/caseyliss\/status\/1507828215338962951\">\n<p>I&rsquo;ve heard from birdies inside that Combine isn&rsquo;t going <em>away<\/em> until SwiftUI divorces itself from Combine. But nobody internal nor external should expect any new development on it.<\/p>\n<\/blockquote>\n\n<p>See also <a href=\"https:\/\/forums.swift.org\/t\/relation-to-combine-framework\/56236\/2\">Philippe Hausler<\/a>.<\/p>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2021\/09\/21\/swift-5-5-released\/\">Swift 5.5 Released<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2021\/04\/06\/swift-collections-package\/\">Swift &ldquo;Collections&rdquo; Package<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2021\/01\/20\/swift-asyncsequence\/\">Swift AsyncSequence<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2020\/10\/08\/swift-algorithms-package\/\">Swift &ldquo;Algorithms&rdquo; Package<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2019\/06\/03\/swiftui-and-combine\/\">SwiftUI and Combine<\/a><\/li>\n<\/ul>\n\n<p id=\"swift-async-algorithms-package-update-2022-04-13\">Update (2022-04-13): <a href=\"https:\/\/www.donnywals.com\/comparing-use-cases-for-async-sequences-and-publishers\/\">Donny Wals<\/a>:<\/p>\n<blockquote cite=\"https:\/\/www.donnywals.com\/comparing-use-cases-for-async-sequences-and-publishers\/\">\n<p>While the basis of what we can do with both <code>AsyncSequence<\/code> and <code>Publisher<\/code> sounds similar, I would like to explore some of the differences between the two mechanisms in a series of two posts.<\/p>\n<p>[&#8230;]<\/p>\n<p>The post you&rsquo;re reading now will focus on comparing use cases. If you want to learn more about lifecycle management, take a look at <a href=\"https:\/\/donnywals.com\/comparing-lifecycle-management-for-async-sequences-and-publishers\">this post<\/a>.<\/p>\n<\/blockquote>\n\n<p id=\"swift-async-algorithms-package-update-2023-06-09\">Update (2023-06-09): <a href=\"https:\/\/mastodon.social\/@nicklockwood\/110504181502249018\">Nick Lockwood<\/a>:<\/p>\n<blockquote cite=\"https:\/\/mastodon.social\/@nicklockwood\/110504181502249018\"><p>It&rsquo;s interesting that SwiftUI is now ditching Combine (which was really its last remaining use-case after Swift Concurrency shipped) - I can&rsquo;t recall another case of Apple walking back a new framework so quickly and thoroughly.<\/p><\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/krzyzanowskim\/status\/1666781529584939010\">Marcin Krzyzanowski<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/krzyzanowskim\/status\/1666781529584939010\"><p>Combine.framework &#x1FAA6;2023<\/p><p>I&rsquo;m so sorry for everyone who builds a career around the framework, it kinda sucks<\/p><\/blockquote>\n\n<p><a href=\"https:\/\/mastodon.social\/@Catfish_Man\/110504458778800974\">David Smith<\/a>:<\/p>\n<blockquote cite=\"https:\/\/mastodon.social\/@Catfish_Man\/110504458778800974\">\n<p>The Autolayout engine was one of the two things that ever adopted the ObjC version, used it for many years.<\/p>\n<\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2023\/06\/06\/wwdc-2023-links\/\">WWDC 2023 Links<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2022\/12\/16\/swift-pitch-observation\/\">Swift Pitch: Observation<\/a><\/li>\n<\/ul>\n\n<p id=\"swift-async-algorithms-package-update-2024-10-08\">Update (2024-10-08): <a href=\"https:\/\/blog.jacobstechtavern.com\/p\/migrating-combine-to-asyncalgorithms\">Jacob Bartlett<\/a>:<\/p>\n<blockquote cite=\"https:\/\/blog.jacobstechtavern.com\/p\/migrating-combine-to-asyncalgorithms\">\n<p>Today, I&rsquo;ll demonstrate how to migrate your Combine code over to AsyncAlgorithms, with a fully open-source tutorial project you can code along with.<\/p>\n<\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2024\/10\/01\/swift-concurrency-and-objective-c\/\">Swift Concurrency and Objective-C<\/a><\/li>\n<\/ul>\n\n<p id=\"swift-async-algorithms-package-update-2024-12-10\">Update (2024-12-10): <a href=\"https:\/\/indieweb.social\/@brentsimmons\/113608076373011079\">Brent<\/a> <a href=\"https:\/\/indieweb.social\/@brentsimmons\/113608096498907697\">Simmons<\/a>:<\/p>\n<blockquote cite=\"https:\/\/indieweb.social\/@brentsimmons\/113608076373011079\">\n<p>I keep telling the younger developers &ldquo;stop doing Combine!&rdquo; and&#8230; they keep doing Combine.<\/p>\n<\/blockquote>\n<blockquote cite=\"https:\/\/indieweb.social\/@brentsimmons\/113608096498907697\">\n<p>I get that &ldquo;stop doing Combine!&rdquo; sounds like an old guy thing to say &mdash; but I&rsquo;m in on Swift structured concurrency and SwiftUI.<\/p>\n<p>My argument is the opposite of curmudgeonly &mdash; Combine is not the future, and we want to use future things.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Tony Parker (tweet): AsyncAlgorithms is a package for algorithms that work with values over time. That includes those primarily about time, like debounce and throttle, but also algorithms about order like combineLatest and merge. Operations that work with multiple inputs (like zip does on Sequence) can be surprisingly complex to implement, with subtle behaviors and [&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":"2022-03-28T20:35:55Z","apple_news_api_id":"6996b1be-45f5-44c4-a2fb-172bb8d3905b","apple_news_api_modified_at":"2024-12-10T16:43:30Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAw==","apple_news_api_share_url":"https:\/\/apple.news\/AaZaxvkX1RMSi-xcruNOQWw","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,31,2078,30,2077,74,71,2200,901],"class_list":["post-35398","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-combine-framework","tag-ios","tag-ios-15","tag-mac","tag-macos-12","tag-opensource","tag-programming","tag-swift-concurrency","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/35398","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=35398"}],"version-history":[{"count":5,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/35398\/revisions"}],"predecessor-version":[{"id":46109,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/35398\/revisions\/46109"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=35398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=35398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=35398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}