Created
October 6, 2017 18:17
-
-
Save moiseev/afd255ebd03938db848cd02021bc4a0b 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