Lapsed coder. Read about variadic generics finally getting into the language. Tried out an example in a playground, couldn't figure out how to make it work.
struct MyType<First: Comparable, Second: Comparable, each Suffix: Comparable>
{
typealias Element = (First, Second, repeat each Suffix)
typealias RotatedElement = (Second, repeat each Suffix, First)
static func rotate(e: Element) -> RotatedElement {
// What goes here? "repeat each e.2" didn't seem to work.
return (e.1, ???, e.0)
}
static func rotateBack(e: RotatedElement) -> Element {
// The last term is just a placeholder. The question
// is how do I reference the last element of the
// incoming tuple, to explicitly reference it into the
// first element of the outgoing tuple?
return (e.???, e.0, repeat each e.1)
}
}
Is there any sort of #variadicCount(???)
operator?
There was some sort of function hack, but how could I explode the tuple's middle members to separate parameters?
I first tried on Reddit.