# \#variadic-generics

**URL:** https://forums.swift.org/tag/variadic-generics/760.md

[Latest](https://forums.swift.org/latest.md) · [Categories](https://forums.swift.org/categories.md) · [Tags](https://forums.swift.org/tags.md)

---

## [Why can't a variadic generic initailizer (that allows zero arguments) count for a protocol's default initializer requirement?](https://forums.swift.org/t/why-cant-a-variadic-generic-initailizer-that-allows-zero-arguments-count-for-a-protocols-default-initializer-requirement/88095)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 5\
**Last updated:** [July 7, 2026, 12:38am UTC](https://forums.swift.org/t/why-cant-a-variadic-generic-initailizer-that-allows-zero-arguments-count-for-a-protocols-default-initializer-requirement/88095 "2026-07-07T00:38:52Z")

</div>

Continuing the discussion from How could someone delegate to a generic-style variadic initializer?: In other words, shouldn't init\<each S\>(\_ somethings: repeat each S) { /\*...\*/ } be able to count as implementing in…

---

## [How could someone delegate to a generic-style variadic initializer?](https://forums.swift.org/t/how-could-someone-delegate-to-a-generic-style-variadic-initializer/88007)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 2\
**Last updated:** [July 6, 2026, 9:32pm UTC](https://forums.swift.org/t/how-could-someone-delegate-to-a-generic-style-variadic-initializer/88007 "2026-07-06T21:32:07Z")

</div>

init\<each S: MyProtocol\>(\_ somethings: repeat each S) { /\*...\*/ } init\<S: MyProtocol\>(\_ elements: some Sequence\<S\>) { /\*...\*/ } This type is going to conform to a protocol that includes a zero-argument initializer. …

---

## [Variadic initializers can't be default initializers?](https://forums.swift.org/t/variadic-initializers-cant-be-default-initializers/86686)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 3\
**Last updated:** [May 13, 2026, 11:09pm UTC](https://forums.swift.org/t/variadic-initializers-cant-be-default-initializers/86686 "2026-05-13T23:09:46Z")

</div>

Here's my code: extension MyType: SetAlgebra { //... public init\<each S: StringProtocol\>(\_ string: repeat each S) { var result = \[String\]() for s in repeat each string { result.append(s.decomposedStri…

---

## [Incorrect code generated with Swift 6.2, whereas 6.1.2 refuses to compile due to "broken module found"](https://forums.swift.org/t/incorrect-code-generated-with-swift-6-2-whereas-6-1-2-refuses-to-compile-due-to-broken-module-found/81602)

<div class="topic-metadata">

**Author:** [@George](https://forums.swift.org/u/George)\
**Replies:** 0\
**Last updated:** [August 12, 2025, 4:13am UTC](https://forums.swift.org/t/incorrect-code-generated-with-swift-6-2-whereas-6-1-2-refuses-to-compile-due-to-broken-module-found/81602 "2025-08-12T04:13:43Z")

</div>

I’ve written up the issue in detail here: Program utilizing variadic generics crashes at runtime with a double-free · Issue #83659 · swiftlang/swift · GitHub To summarize, I’m having some issues with a module I’m workin…

---

## [Accessing the "tail" of a parameter pack](https://forums.swift.org/t/accessing-the-tail-of-a-parameter-pack/81551)

<div class="topic-metadata">

**Author:** [@George](https://forums.swift.org/u/George)\
**Replies:** 2\
**Last updated:** [August 8, 2025, 10:01pm UTC](https://forums.swift.org/t/accessing-the-tail-of-a-parameter-pack/81551 "2025-08-08T22:01:54Z")

</div>

I may be missing something obvious, but I haven’t been able to make the following code work: struct Foo\<each T\> { let values: (repeat each T) } struct Bar\<each U\> { let foo: Foo\<Void, repeat each U\> …

---

## [Opaque return type fails when using variadic generics](https://forums.swift.org/t/opaque-return-type-fails-when-using-variadic-generics/81120)

<div class="topic-metadata">

**Author:** [@George](https://forums.swift.org/u/George)\
**Replies:** 0\
**Last updated:** [July 15, 2025, 3:58am UTC](https://forums.swift.org/t/opaque-return-type-fails-when-using-variadic-generics/81120 "2025-07-15T03:58:03Z")

</div>

I'm running into another issue that I'd love any advice on how to work around. I've filed a bug here: Type with parameter pack argument fails to be erased to an opaque type. · Issue #83055 · swiftlang/swift · GitHub Bas…

---

## [Cannot mangle free standing archetype](https://forums.swift.org/t/cannot-mangle-free-standing-archetype/81071)

<div class="topic-metadata">

**Author:** [@George](https://forums.swift.org/u/George)\
**Replies:** 2\
**Last updated:** [July 13, 2025, 1:29am UTC](https://forums.swift.org/t/cannot-mangle-free-standing-archetype/81071 "2025-07-13T01:29:48Z")

</div>

Hi! I'm running into an annoying crash related to variadic generics with the error message "Cannot mangle free-standing archetype" I've posted an issue here: Cannot mangle free-standing archetype · Issue #83021 · swiftl…

---

## [Crash creating key path to variadic property](https://forums.swift.org/t/crash-creating-key-path-to-variadic-property/80671)

<div class="topic-metadata">

**Author:** [@George](https://forums.swift.org/u/George)\
**Replies:** 1\
**Last updated:** [June 25, 2025, 11:32pm UTC](https://forums.swift.org/t/crash-creating-key-path-to-variadic-property/80671 "2025-06-25T23:32:27Z")

</div>

The following code consistently crashes for me when creating the key path on both 6.1 and the 6.2 betas: struct Foo\<each T\> { struct Bar { let bar: (repeat each T) } func bar() { // Crashes here …

---

## [Accessing particular elements in a variadic tuple](https://forums.swift.org/t/accessing-particular-elements-in-a-variadic-tuple/80277)

<div class="topic-metadata">

**Author:** [@George](https://forums.swift.org/u/George)\
**Replies:** 8\
**Last updated:** [June 4, 2025, 3:18pm UTC](https://forums.swift.org/t/accessing-particular-elements-in-a-variadic-tuple/80277 "2025-06-04T15:18:12Z")

</div>

I'm finding myself needing a facility to access specific elements in a variadic tuple from time to time. Currently, I'm doing something like this: struct VariadicTupleAccessor\<each Element\>: Sendable { init() { …

---

## [Variadic generics crash when parameter pack is used in a closure's arguments](https://forums.swift.org/t/variadic-generics-crash-when-parameter-pack-is-used-in-a-closures-arguments/79449)

<div class="topic-metadata">

**Author:** [@George](https://forums.swift.org/u/George)\
**Replies:** 0\
**Last updated:** [April 22, 2025, 7:02pm UTC](https://forums.swift.org/t/variadic-generics-crash-when-parameter-pack-is-used-in-a-closures-arguments/79449 "2025-04-22T19:02:23Z")

</div>

I'm running into a crash relating to variadic generics that I haven't found a workaround for, and I'm hoping someone with more knowledge of compiler internals can suggest something. I've reduced the problematic code to: …

---

## [How do I rewrite zip function by the new "repeat each" syntax?](https://forums.swift.org/t/how-do-i-rewrite-zip-function-by-the-new-repeat-each-syntax/79138)

<div class="topic-metadata">

**Author:** [@haifengkao](https://forums.swift.org/u/haifengkao)\
**Replies:** 4\
**Last updated:** [April 7, 2025, 9:37pm UTC](https://forums.swift.org/t/how-do-i-rewrite-zip-function-by-the-new-repeat-each-syntax/79138 "2025-04-07T21:37:04Z")

</div>

This is what I got so far. I don't know how to express "the Dependencies of each MiddlewareReader should be the same" extension MiddlewareReaderProtocol { public static func zip\<each M: MiddlewareReaderProtocol, MO…

---

## [Parameter packs, same-shape requirements, and spreading arrays](https://forums.swift.org/t/parameter-packs-same-shape-requirements-and-spreading-arrays/79043)

<div class="topic-metadata">

**Author:** [@NSExceptional](https://forums.swift.org/u/NSExceptional)\
**Replies:** 4\
**Last updated:** [April 5, 2025, 11:10pm UTC](https://forums.swift.org/t/parameter-packs-same-shape-requirements-and-spreading-arrays/79043 "2025-04-05T23:10:02Z")

</div>

A few things that I wish I could do with parameter packs appear to be impossible. I'll outline my use case here. I'm working with SwiftSyntax, looking for instances of layer.cornerRadius = blah: let list = CodeBlockIte…

---

## [Variadic types: "Same-element requirements are not yet supported"](https://forums.swift.org/t/variadic-types-same-element-requirements-are-not-yet-supported/67285)

<div class="topic-metadata">

**Author:** [@toastersocks](https://forums.swift.org/u/toastersocks)\
**Replies:** 17\
**Last updated:** [March 25, 2025, 9:33pm UTC](https://forums.swift.org/t/variadic-types-same-element-requirements-are-not-yet-supported/67285 "2025-03-25T21:33:26Z")

</div>

I was really excited to replace a lot of my repetitive declarations like: func combineLatest\<B: Publisher, C: Publisher, D: Publisher, E: Publisher\>(\_ b: B, \_ c: C, \_ d: D, \_ e: E) -\> AnyPublisher\<(Output, B.Output, C.O…

---

## [How to write @Sendable function composition by parameter packs and function overloading?](https://forums.swift.org/t/how-to-write-sendable-function-composition-by-parameter-packs-and-function-overloading/78497)

<div class="topic-metadata">

**Author:** [@haifengkao](https://forums.swift.org/u/haifengkao)\
**Replies:** 1\
**Last updated:** [March 18, 2025, 12:33pm UTC](https://forums.swift.org/t/how-to-write-sendable-function-composition-by-parameter-packs-and-function-overloading/78497 "2025-03-18T12:33:49Z")

</div>

The compiler will complain about ambiguous function calls if I provide @Sendable function composition and the non-sendable version at the same time. Do I really have to provide the compose function with difference name…

---

## [Making a "Drop First Argument" Function using Variadic Generics](https://forums.swift.org/t/making-a-drop-first-argument-function-using-variadic-generics/69167)

<div class="topic-metadata">

**Author:** [@Anachron](https://forums.swift.org/u/Anachron)\
**Replies:** 6\
**Last updated:** [February 16, 2025, 4:49am UTC](https://forums.swift.org/t/making-a-drop-first-argument-function-using-variadic-generics/69167 "2025-02-16T04:49:07Z")

</div>

Hey there, I just triggered a compiler error (I think): "INTERNAL ERROR: feautre not implemented: reabstraction of pack values". Here's my minimal example to reproduce this: func dropFirstArg\<First, each Others\>(\_ clos…

---

## [Compiler can't infer types with Parameter Packs containing more than three elements](https://forums.swift.org/t/compiler-cant-infer-types-with-parameter-packs-containing-more-than-three-elements/77524)

<div class="topic-metadata">

**Author:** [@danielhall](https://forums.swift.org/u/danielhall)\
**Replies:** 8\
**Last updated:** [January 31, 2025, 12:53am UTC](https://forums.swift.org/t/compiler-cant-infer-types-with-parameter-packs-containing-more-than-three-elements/77524 "2025-01-31T00:53:49Z")

</div>

Hello! I'm trying to create a container type that hold a root type, plus n number of additional types that conform to a protocol. This works well with Parameter Packs, except that any time the number of additional types …

---

## [Instantiate a parameter pack from an array](https://forums.swift.org/t/instantiate-a-parameter-pack-from-an-array/77484)

<div class="topic-metadata">

**Author:** [@richy486](https://forums.swift.org/u/richy486)\
**Replies:** 4\
**Last updated:** [January 30, 2025, 8:58am UTC](https://forums.swift.org/t/instantiate-a-parameter-pack-from-an-array/77484 "2025-01-30T08:58:49Z")

</div>

We have an app that creates controls to set parameters on a component view. We do this with parameter packs, its great and saved us a lot of time when adding new components. e.g. struct SandboxView\<each Option, Content…

---

## [Pitch: User-defined tuple conformances](https://forums.swift.org/t/pitch-user-defined-tuple-conformances/67154)

<div class="topic-metadata">

**Author:** [@Slava\_Pestov](https://forums.swift.org/u/Slava_Pestov)\
**Replies:** 38\
**Last updated:** [January 27, 2025, 1:40pm UTC](https://forums.swift.org/t/pitch-user-defined-tuple-conformances/67154 "2025-01-27T13:40:39Z")

</div>

Tuple conformances Authors: Slava Pestov Status: Implementation in progress Upcoming Feature Flag: TupleConformances Previous Proposal: SE-0283 Tuples Conform to Equatable, Comparable, and Hashable Review: (pitch) Intr…

---

## [Passing a parameter pack to a function call fails to compile](https://forums.swift.org/t/passing-a-parameter-pack-to-a-function-call-fails-to-compile/72243)

<div class="topic-metadata">

**Author:** [@JaapWijnen](https://forums.swift.org/u/JaapWijnen)\
**Replies:** 12\
**Last updated:** [January 18, 2025, 8:06am UTC](https://forums.swift.org/t/passing-a-parameter-pack-to-a-function-call-fails-to-compile/72243 "2025-01-18T08:06:30Z")

</div>

Playing around with parameter packs I was trying to compile the following but failed. Now this feels like it's either a bug in the compiler or I'm doing something wrong using the parameter pack feature :) Would love to u…

---

## [Is it possible to constrain variadic generics to a particular type](https://forums.swift.org/t/is-it-possible-to-constrain-variadic-generics-to-a-particular-type/76333)

<div class="topic-metadata">

**Author:** [@bjhomer](https://forums.swift.org/u/bjhomer)\
**Replies:** 3\
**Last updated:** [December 2, 2024, 4:08pm UTC](https://forums.swift.org/t/is-it-possible-to-constrain-variadic-generics-to-a-particular-type/76333 "2024-12-02T16:08:11Z")

</div>

I have a function that converts an array into a tuple, if the element count is correct. For example: let array = \[1, 2, 3\] guard let (a, b, c) = array.explode() else { fatalError("The array must not have had 3 element…

---

## [Language limitation, or am I not doing this right? \`Error: Pack expansion requires that 'each Element' and 'repeat each Element' have the same shape\`](https://forums.swift.org/t/language-limitation-or-am-i-not-doing-this-right-error-pack-expansion-requires-that-each-element-and-repeat-each-element-have-the-same-shape/75936)

<div class="topic-metadata">

**Author:** [@toastersocks](https://forums.swift.org/u/toastersocks)\
**Replies:** 3\
**Last updated:** [November 11, 2024, 3:59pm UTC](https://forums.swift.org/t/language-limitation-or-am-i-not-doing-this-right-error-pack-expansion-requires-that-each-element-and-repeat-each-element-have-the-same-shape/75936 "2024-11-11T15:59:23Z")

</div>

I'm trying to write a variadic zip function that will take a function A... -\> B, and returns a function Functor\<A\>... -\> Functor\<B\>. I feel like I'm close, but am running into an error and I'm not sure if this is just a …

---

## [Spelling empty parameter packs as just type identifier](https://forums.swift.org/t/spelling-empty-parameter-packs-as-just-type-identifier/75617)

<div class="topic-metadata">

**Author:** [@Val](https://forums.swift.org/u/Val)\
**Replies:** 2\
**Last updated:** [October 25, 2024, 1:44pm UTC](https://forums.swift.org/t/spelling-empty-parameter-packs-as-just-type-identifier/75617 "2024-10-25T13:44:30Z")

</div>

Would it be possible to enable spelling empty parameter packs as just the type identifier? We have this Callback typealias defined, and it's somewhat unfortunate to always have to spell Callback\<\> for the very common emp…

---

## [How can we write to a parameter-pack tuple with the iteration syntax?](https://forums.swift.org/t/how-can-we-write-to-a-parameter-pack-tuple-with-the-iteration-syntax/74834)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 2\
**Last updated:** [October 22, 2024, 9:31pm UTC](https://forums.swift.org/t/how-can-we-write-to-a-parameter-pack-tuple-with-the-iteration-syntax/74834 "2024-10-22T21:31:11Z")

</div>

func myFunction\<each T: FixedWidthInteger\>(\_ t: repeat each T) -\> (repeat each T) { for value in repeat each t { print(value) } var result = (repeat each t) for dummy in repeat each ??? { // \`result\`, or \`&r…

---

## [Compiler unable to infer type in case of multiple parameter packs](https://forums.swift.org/t/compiler-unable-to-infer-type-in-case-of-multiple-parameter-packs/75209)

<div class="topic-metadata">

**Author:** [@soumyamahunt](https://forums.swift.org/u/soumyamahunt)\
**Replies:** 0\
**Last updated:** [October 7, 2024, 4:38pm UTC](https://forums.swift.org/t/compiler-unable-to-infer-type-in-case-of-multiple-parameter-packs/75209 "2024-10-07T16:38:36Z")

</div>

I have a macro with following definition: @attached(peer) @available(swift 5.9) public macro CodedBy\<Parent, Helper: HelperCoder, each Argument, each Property\>( \_ helperAction: (repeat each Argument, repeat each Pro…

---

## [Can we mutate through variadic generic pack iteration?](https://forums.swift.org/t/can-we-mutate-through-variadic-generic-pack-iteration/74865)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 1\
**Last updated:** [September 23, 2024, 1:46am UTC](https://forums.swift.org/t/can-we-mutate-through-variadic-generic-pack-iteration/74865 "2024-09-23T01:46:05Z")

</div>

I saw this in Swift's blog, in an article about pack iteration: func allEmpty\<each T\>(\_ array: repeat \[each T\]) -\> Bool { for a in repeat each array { guard a.isEmpty else { return false } } return true } Th…

---

## [Is there a way to reverse a tuple?](https://forums.swift.org/t/is-there-a-way-to-reverse-a-tuple/74831)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 3\
**Last updated:** [September 22, 2024, 1:04pm UTC](https://forums.swift.org/t/is-there-a-way-to-reverse-a-tuple/74831 "2024-09-22T13:04:25Z")

</div>

Is there a way (in Swift 6) to reverse the members of a tuple, i.e. given a tuple of type (A, B, C), return a tuple of (C, B, A)? It still needs to work when the variadic length is 0 or 1.

---

## [Calculate shape of N-dimensional array from a flat array](https://forums.swift.org/t/calculate-shape-of-n-dimensional-array-from-a-flat-array/74553)

<div class="topic-metadata">

**Author:** [@wigging](https://forums.swift.org/u/wigging)\
**Replies:** 11\
**Last updated:** [September 14, 2024, 6:56pm UTC](https://forums.swift.org/t/calculate-shape-of-n-dimensional-array-from-a-flat-array/74553 "2024-09-14T18:56:57Z")

</div>

I have a flat array as shown below that represents a 3D array. The example prints the shape of the array as (2, 3, 4) which means there are two arrays each with a size of 3-by-4 elements. let arr = \[\[\[1, 2, 3, 4\], …

---

## [Is \`sending\` supported by variadic generics?](https://forums.swift.org/t/is-sending-supported-by-variadic-generics/74394)

<div class="topic-metadata">

**Author:** [@dehesa](https://forums.swift.org/u/dehesa)\
**Replies:** 4\
**Last updated:** [September 6, 2024, 8:35am UTC](https://forums.swift.org/t/is-sending-supported-by-variadic-generics/74394 "2024-09-06T08:35:39Z")

</div>

I am trying to transfer non-sendable variadic generics values to a function through the sending keyword. However, I don't seem to be able to use it correctly. struct Runner { func run\<each Value\>(\_ value: repeat each …

---

## [Parameter packs: Creating an \`Equatable\` box](https://forums.swift.org/t/parameter-packs-creating-an-equatable-box/67880)

<div class="topic-metadata">

**Author:** [@stuchlej](https://forums.swift.org/u/stuchlej)\
**Replies:** 5\
**Last updated:** [August 16, 2024, 4:41pm UTC](https://forums.swift.org/t/parameter-packs-creating-an-equatable-box/67880 "2024-08-16T16:41:07Z")

</div>

Hello, I have experienced a bug in a compiler (crash, see below). I would like to ask how did you solve this issue. Essentially, I need to pass parameters from my variadic API into an API, that accepts an Equatable con…

---

## [Are same-type variadic generic requirements available is some Swift version?](https://forums.swift.org/t/are-same-type-variadic-generic-requirements-available-is-some-swift-version/73663)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 4\
**Last updated:** [August 6, 2024, 1:18pm UTC](https://forums.swift.org/t/are-same-type-variadic-generic-requirements-available-is-some-swift-version/73663 "2024-08-06T13:18:09Z")

</div>

I'm talking about things like: func variadic\<each S: Sequence, T\>(\_: repeat each S) where repeat (each S).Element == T {} I wanted an initializer that took in many different types with the same protocol conformance and…

[Next page](https://forums.swift.org/tag/variadic-generics/760.md?match_all_tags=true&page=1&tags%5B%5D=variadic-generics)
