How to use parameter packs to "combine" a generic type?

I'm trying to add a "combining" operation to a generic type using parameter packs but I can't get it to compile:

struct Box<Value> {
  let value: Value
  func zip<each A, each B>(
    _ other: Box<(repeat each B)>
  ) -> Box<(repeat each A, repeat each B)>
  where Value == (repeat each A) {
    Box<(repeat each A, repeat each B)>(
      value: (repeat each value, repeat each other.value)
    )
  }
}

It crashes the compiler (which I filed here), but I was wondering if there was a workaround or if I'm holding things wrong?

2 Likes

I'm not sure if this works for your use case, but lifting the parameter pack to the type compiles for me:

struct Box<each Value> {
    var value: (repeat each Value)
    
    func zip<each Other>(
        _ other: Box<repeat each Other>
    ) -> Box<(repeat each Value, repeat each Other)> {
        .init(value: (repeat each value, repeat each other.value))
    }
}

Unfortunately not, but thanks for trying!