# Variadic generics discussion

**URL:** <https://forums.swift.org/t/variadic-generics-discussion/2817>\
**Category:** Discussion\
**Created:** [May 28, 2016, 8:03pm UTC](https://forums.swift.org/t/variadic-generics-discussion/2817 "2016-05-28T20:03:30Z")\
**Posts on this page:** 1\
**Showing post:** 75

<div class="post-metadata">

**Author:** ![twof](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/twof/32/1628_2.png) [@twof](https://forums.swift.org/u/twof)\
**Post date:** [January 25, 2018, 2:00pm UTC](https://forums.swift.org/t/variadic-generics-discussion/2817/75 "2018-01-25T14:00:34Z")

</div>

> [@xwu](#):
>
> I think you missed the point of my message. Wouldn’t you agree that there’s clearly interest in the feature, given the extensive discussion? Do you think that another “bump” was necessary to demonstrate interest?

Yes I do. It's been two years and two Swift versions since there was any real discussion on the topic at least as far as I could tell from a forum search. I think a lot has changed since then and we've learned quite a bit that might feed into new opinions. I'd also love to see if people feel this is something that is within scope for Swift 5. If not, then discussion can still happen knowing that variadic generics will need to be pushed to Swift 6 or beyond.

There is one other discussion on variadic generics that happened last year, but it looks like it mostly devolved to a discussion on whether or not tuples should exist:

> [@Checking in; more thoughts on arrays and variadic generics](https://forums.swift.org/t/checking-in-more-thoughts-on-arrays-and-variadic-generics/4948):
>
> 1. Variadic generics When I look at SwiftDoc.org \<[http://swiftdoc.org/&gt;](http://swiftdoc.org/&gt;), I see some functions repeated with differing numbers of parameters. This seems like a job for variadic templates^H^H^H^H^H^H^H^H^H generics, like in C++. Fortunately, someone has already wrote about this, at \<[swift/GenericsManifesto.md at main · apple/swift · GitHub](https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md#variadic-generics&gt;%5C). A new idea I came up with is that both homogeneous (the current support) and heterogeneous variadic parameters can appear in function declarations. Each ca…

I'm interested in this because I'm working on a command line tools framework that would benefit. Currently, if I want a command line tool to be able to take parameters and have those parameters be type-safe, I have to restrict the tool's parameters to a single type.

```
Command<U: LosslessStringConvertible>(
    triggers: [String],
    help: String,
    numParams: NumberOfParams = .any,
    options: [ProtoOption]=[],
    onExecution: @escaping ([U], State) throws -> ()
)

```

In the current state someone couldn't accept a command like `newperson Alex 10` passing in parameters for name and age, unless they wanted to also cast 10 to a `String` and deal with it at runtime.

However, with variadic generics, the type could look something more like (Using C++ syntax)

```
Command<...U: LosslessStringConvertible>(
    triggers: [String],
    help: String,
    numParams: NumberOfParams = .any,
    options: [ProtoOption]=[],
    onExecution: @escaping (State, U...) throws -> ()
)

```

The feature required here is the ability to take a variadic generic type signature, and unpack it for use as the parameter type of an instance, static, or anonymous function.

I'm interested to see what other use cases people can think of 😀

---

_[View the full topic](https://forums.swift.org/t/variadic-generics-discussion/2817)._
