{"id":41014,"date":"2023-11-07T14:28:29","date_gmt":"2023-11-07T19:28:29","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=41014"},"modified":"2023-11-07T14:29:06","modified_gmt":"2023-11-07T19:29:06","slug":"swift-proposal-pack-iteration","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2023\/11\/07\/swift-proposal-pack-iteration\/","title":{"rendered":"Swift Proposal: Pack Iteration"},"content":{"rendered":"<p><a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0408-pack-iteration.md\">SE-0408<\/a>:<\/p>\n<blockquote cite=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0408-pack-iteration.md\">\n<p>Currently, it is possible to express list operations on value packs using pack expansion expressions. This approach requires putting code involving statements into a function or closure. For example, limiting repetition patterns to expressions does not allow for short-circuiting with <code>break<\/code> or <code>continue<\/code> statements, so the pattern expression will always be evaluated once for every element in the pack. The only way to stop evaluation would be to mark the function\/closure containing the pattern expression throwing, and catch the error in a do\/catch block to return, which is unnatural for Swift users.<\/p>\n<p>[&#8230;]<\/p>\n<p>We propose allowing iteration over value packs using <code>for-in<\/code> loops. With the adoption of pack iteration, the implementation of the standard library methods like <code>==<\/code> operator for tuples of any number of elements will become straightforward.<\/p>\n<\/blockquote>\n<p>It&rsquo;s accepted.<\/p>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2023\/03\/24\/swift-proposal-value-and-type-parameter-packs\/\">Swift Proposal: Value and Type Parameter Packs<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>SE-0408: Currently, it is possible to express list operations on value packs using pack expansion expressions. This approach requires putting code involving statements into a function or closure. For example, limiting repetition patterns to expressions does not allow for short-circuiting with break or continue statements, so the pattern expression will always be evaluated once for [&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":"2023-11-07T19:28:31Z","apple_news_api_id":"36ea6b8b-4504-4f0b-9503-4111cb5301e8","apple_news_api_modified_at":"2023-11-07T19:29:09Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAQ==","apple_news_api_share_url":"https:\/\/apple.news\/ANupri0UETwuVA0ERy1MB6A","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":[46,71,901],"class_list":["post-41014","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-languagedesign","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/41014","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=41014"}],"version-history":[{"count":3,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/41014\/revisions"}],"predecessor-version":[{"id":41017,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/41014\/revisions\/41017"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=41014"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=41014"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=41014"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}