Is it possible to extend an generic class for a specialised/constructed generic type? I would like to extend Int Arrays with a method to calculate the sum of its elements.>
extension Array {
func sum () -> Int? {
guard self.count > 0 && self.first is Int else {
return nil
}
var s = 0
forEach {
s += $0 as! Int
}
return s
}
}