Currently, func average() -> Double is defined as an extension on Collection where Element == Double. What about CGFloats?
I suggest to add a protocol Field (based on algebraic fields) providing addition, multiplication and division with Self elements, and also a zero and one element. This would allow both average() and sum() to be implemented more generically. Double, Float and CGFloat could conform to this protocol (with nearly no additional implementation effort).
The integer case would have to be treated specially though.
Currently,
func average() -> Doubleis defined as an extension onCollection where Element == Double. What aboutCGFloats?I suggest to add a protocol
Field(based on algebraic fields) providing addition, multiplication and division withSelfelements, and also azeroandoneelement. This would allow bothaverage()andsum()to be implemented more generically.Double,FloatandCGFloatcould conform to this protocol (with nearly no additional implementation effort).The integer case would have to be treated specially though.