Skip to content

Instantly share code, notes, and snippets.

@ekinhbayar
Last active June 28, 2018 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ekinhbayar/0b6c14353caad65e6f83ec37b26d7ef4 to your computer and use it in GitHub Desktop.
Save ekinhbayar/0b6c14353caad65e6f83ec37b26d7ef4 to your computer and use it in GitHub Desktop.
struct Buffer {
var count: Int
subscript(at: Int) -> Any {
// get/set from storage
}
}
struct Buffer <Element> {
let count: Int
subscript(at: Int) -> Element
// fetch from storage
}
}
extension Buffer where Element: Numeric {
func sum() -> Element {
var total: Element = 0
for i in 0..<self.count {
total += self[i]
}
}
return total
}
}
let total = numbers.sum()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment