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 in the Parameter Packs exceeds three, the compiler throws an error and can't infer the type anymore. This requires a lot of extra code to work around inference issues and use the Expanded type with multiple elements.
Am I doing something wrong here? Or is there a workaround that would let me keep calling addingExpansion as many times as needed?
struct Expanded<Base, each Expansion> {
fileprivate let base: Base
fileprivate let expansions: (repeat each Expansion)
init(base: Base, expansions: (repeat each Expansion)) {
self.base = base
self.expansions = (repeat each expansions)
}
public func addingExpansion<New>(_ expansion: New) -> Expanded<Base, repeat each Expansion, New> {
.init(base: base, expansions: (repeat each expansions, expansion))
}
}
struct One { }
struct Two { }
struct Three { }
struct Four { }
let initial = Expanded(base: "", expansions: One())
var more = initial
.addingExpansion(Two())
.addingExpansion(Three())
.addingExpansion(Four())
print(more)
Thanks for the great notes and suggested workarounds! Yes, I also ran into the bizarre type mismatch error for two exactly identical types
That approach of just taking multiple expansions as variadic parameters rather than chaining multiple calls with single parameters each works well enough!
Sorry, that was a terrible choice of words. I certainly did not mean it to come across as asking you folks to do my job. I meant to ask if Daniel wishes to make the contribution himself and track fixes.
And thank you for reporting this @danielhall. The more test cases, the better.
Hi @anthonylatsis, thanks for replying to this thread! Sure, I'd happy to open an issue but it looks like @stephencelis is already a step ahead there! Happy to provide anything else that can help though.