Last active
June 28, 2018 08:12
-
-
Save ekinhbayar/0b6c14353caad65e6f83ec37b26d7ef4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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