within a single project, these usually end up evolving into an ArrayBuilder protocol with an Element associatedtype that the actual result builders conform to. but it still gets duplicated across projects. has anyone else had the same experience?
protocol ArrayBuilder
{
associatedtype Element
}
extension ArrayBuilder
{
// all those buildXxx methods
}
@resultBuilder
struct ThingBuilder: ArrayBuilder
{
typealias Element = Thing
// any extra stuff
}
I also had to duplicate this code multiple times in different projects. Could we maybe put a DefaultArrayBuilder protocol into the standard library? I think that would be very useful.
Maybe it could be a bit more flexible than @David_Catmull's solution. I'm thinking about e.g. having an associated type for the expression and the final result.
Having this protocol in the standard library could also help with discoverability of the result builder functions. It's nice that SourceKit is autocompleting them now, but having a simple example implementation would definitely be helpful as well.
i used to do that, but i found that i often wanted to customize the buildFinalResult methods, so gradually started doing the same thing @David_Catmull does.
Happened here too. We have typeable resultbuilders for array, set and dict, but it is the array one that is most of the time is used.
It would make sense to see this being part of the standard library.