What's the syntax for extending an Array
with an Element
type of Double
?
I've seen this sort of answer around:
extension Sequence where Iterator.Element == Double {
public func multiply(by factor: Double) -> [Double] {
return self.map { $0 * factor }
}
}
But it's extending a generic Sequence
, so it allows neither random access by index, nor to a count
property. So e.g., I can't implement the following:
public func windowingFunc(index: Int, N: Int) -> Double {
// ...
}
extension Sequence where Iterator.Element == Double {
public func applyWindowing() -> [Double] {
return (0..<self.count).map{self[$0] * windowingFunc(index: $0, N: self.count)}
}
}