I hate to complain because Rule Builders are so magical already, but what if one doesn't want to use a specific type or write a custom ForEach/Repeater type that conforms to the protocol? Is there not a way?
I asked because I had a problem that appeared to be related when I went to add for-loops to a protocol based result builder.
I fixed my specific problem, but I'd like to be able to do something like:
let multiType = Assembly {
Square()
for _ in 0...3 {
//in the "real world" the index would be used to determine characteristics
Circle()
Square()
}
Circle()
}
At this point I don't even care how ugly the underlying data is.
I wrote a Repeating(count:Int) { LayerBuilder } example (in the linked to topic), but I'm hesitant to reimplement for loops when they already exist and are familiar.
You can tell me to just go write javascript if I'm being unreasonable . I'll take the hint.
For clarity, my biggest discomfort is that this works easily and so nicely with a buildOptional implemented:
let maybe = Assembly {
Square()
if showCircle {
Circle()
Circle()
Square()
}
Square()
}
But
let multiType = Assembly {
Square()
for _ in numbers {
Circle()
Circle()
Square()
}
Square()
}
Needs a lot of hoop jumping, a custom implementation actually, to mimic the functionality. The buildArray function only lets you pass one and only one item to the for loop from what I can tell?
Is there a trick I'm not seeing?
What is the difference?