These examples require “path-dependent types” to work. There are some examples in the old enhanced existentials draft (although it does not use the term path-dependent types).
Also, fwiw Scala’s type system supports this feature. I don’t know Scala in depth so I’m not sure how closely it relates to what we might have in Swift but you might find it interesting to look at how Scala handles this.
This would require a map overload in a conditional extension constrained to where Element was an existential, and for which we could name the constraints applied to the existential so they could be used as constraints on the opaque transform parameter type. I’m not sure how we might express that or how useful it would be, but it’s an interesting direction to think about.