This isn't quite what I was getting at. Since (IIRC) builder types can be generic, you can write something like this:
protocol Transformation {
associatedtype Value
func transform(values: [Value]) -> [Value]
}
@_functionBuilder
struct TransformationBuilder<Value> {
static func buildExpression<T: Transformation>(t: T) -> AnyTransformation<Value> where T.Value == Value { ... }
static func buildBlock(transforms: AnyTransformation<Value>) -> AnyTransformation<Value> { ... }
}
func makeTransform<Value>(@TransformationBuilder<Value> builder: () -> AnyTransformation<Value>) -> AnyTransformation<Value> {
builder()
}
Uses of makeTransform
would allow a certain amount of type propagation into the Value
type. I don't know how much of a problem we consider that.