Parameterized associate types are how ML languages model higher kinded types0, but they're free functions (or functions in a module). I think the equivalent would be making a separate mapper type:
protocol Mappable {
associatedtype Container<A>
static func map<Element, Result>(
_ base: Container<Element>,
transform: (Element) -> Result
) -> Container<Result>
}
struct ArrayMapper: Mappable {
typealias Container<A> = [A]
static func map<Element, Result>(
_ base: [Element],
_ transform: (Element) -> Result
) -> [Result]
}
We could then extend array so we still have method syntax:
extension Array {
func map<Result>(_ transform: (Element) -> Result) -> [Result] {
ArrayMapper.map(self, transform)
}
}
I'm not sure how you'd define the protocol so that Container is Self or if it's possible.