{"id":38863,"date":"2023-03-24T14:12:03","date_gmt":"2023-03-24T18:12:03","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=38863"},"modified":"2023-03-24T14:12:03","modified_gmt":"2023-03-24T18:12:03","slug":"swift-proposal-value-and-type-parameter-packs","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2023\/03\/24\/swift-proposal-value-and-type-parameter-packs\/","title":{"rendered":"Swift Proposal: Value and Type Parameter Packs"},"content":{"rendered":"<p><a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0393-parameter-packs.md\">SE-0393<\/a>:<\/p>\n<blockquote cite=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0393-parameter-packs.md\"><p>Many modern Swift libraries include ad-hoc variadic APIs with an arbitrary upper bound, typically achieved with overloads that each have a different fixed number of type parameters and corresponding arguments. Without variadic generic programming support in the language, these ad-hoc variadic APIs have a significant cost on library maintenance and the developer experience of using these APIs.<\/p><p>This proposal adds <em>type parameter packs<\/em> and <em>value parameter packs<\/em> to enable abstracting over the number of types and values with distinct type. This is the first step toward variadic generics in Swift.<\/p>\n<p>[&#8230;]<\/p>\n<p>A parameter pack itself is not a first-class value or type, but the elements of a parameter pack can be used anywhere that naturally accepts a comma-separated list of values or types using <em>pack expansions<\/em>. A pack expansion unpacks the elements of a pack into a comma-separated list, and elements can be appended to either side of a pack expansion by writing more values in the comma-separated list.<\/p>\n<p>A pack expansion consists of the <code>repeat<\/code> keyword followed by a type or an expression. The type or expression that <code>repeat<\/code> is applied to is called the <em>repetition pattern<\/em>. The repetition pattern must contain pack references.<\/p><\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2023\/03\/22\/swift-proposal-noncopyable-structs-and-enums\/\">Swift Proposal: Noncopyable Structs and Enums<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2022\/11\/17\/a-vision-for-variadic-generics-in-swift\/\">A Vision for Variadic Generics in Swift<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2022\/07\/27\/swift-tuple-overloads\/\">Swift Tuple Overloads<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2020\/01\/24\/on-the-road-to-swift-6\/\">On the Road to Swift 6<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>SE-0393: Many modern Swift libraries include ad-hoc variadic APIs with an arbitrary upper bound, typically achieved with overloads that each have a different fixed number of type parameters and corresponding arguments. Without variadic generic programming support in the language, these ad-hoc variadic APIs have a significant cost on library maintenance and the developer experience of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2023-03-24T18:12:05Z","apple_news_api_id":"a88c415c-e1ad-48f9-92ae-3c9197388d22","apple_news_api_modified_at":"2023-03-24T18:12:05Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/AqIxBXOGtSPmSrjyRlziNIg","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-38863","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\/38863","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=38863"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/38863\/revisions"}],"predecessor-version":[{"id":38864,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/38863\/revisions\/38864"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=38863"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=38863"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=38863"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}