-
-
Save sindresorhus/c437ccc59a651e5d59235ef49291faf5 to your computer and use it in GitHub Desktop.
If you really really miss the `/` from `Numeric`...
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
public protocol Dividable { | |
static func / (lhs: Self, rhs: Self) -> Self | |
} | |
extension Int : Dividable {} | |
extension Double : Dividable {} | |
extension Sequence where Element : Numeric & Dividable { | |
func average() -> Element { | |
var i: Element = 0 | |
var total: Element = 0 | |
for value in self { | |
total = total + value | |
i += 1 | |
} | |
return total / i | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment