+1.
I'm very surprised at this proposal, in terms of its strong ability.
When I read previous discussion about variadic generics, I found this comment. It cannot be expressed by simple variadic generics, because it's hard to express the exact type of result. While variadic generics struggle to do that, buildPartialBlock
can easily do that.
static func buildPartialBlock<A, B>(first: (A) -> B) -> (A) -> B {
return first
}
static func buildPartialBlock<A, B, C>(accumulated: (A) -> B, next: (B) -> C) -> (A) -> C {
return { (x: A) in next(accumulated(x)) }
}
func f(_: A) -> B
func g(_: B) -> C
func h(_: C) -> D
let hgf: (A) -> D = Chain {
f
g
h
}
Considering this, I feel we should put more thought on how result builders interact with variadic generics. I don't have solid vision of them, but they definitely correlate with each other.