extension Array {
func flatten<T>() -> T[] {
let xs = (self as Any) as Array<Array<T>>
return xs.reduce(T[](), +)
}
}
It works, but I'm not sure if all those casts are required.
Is there a better way?
For comparison, here is the implementation in one of the swift extension libraries. I'm not sure if they have it all figured out too -- their implementation begins with the following comment:
// There's still some work to do here