In Swift, one can extend a sequence that contains elements of a particular type, e.g.:
extension SequenceType where Generator.Element == Rect {
func intersection() -> Rect? { ... }
}
// when using
let intersection = [rect1, rect2, rect3].intersection()
which is nice. However, how can I do the same thing if Rect itself is a generic type (e.g. Rect<Float>
, Rect<Double>
etc.)? I tried
extension SequenceType where Generator.Element == Rect<T>
but the compiler complains about 'undeclared type T'. I can't quite figure out where to put it. Right now, I have to specialise for every floating-point type.