-
-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement average()
for more numeric types
#36
Comments
CGFloats are Doubles. It's just a typealias. Just command-click it and you'll be amazed. ;) Please note that there are many libraries providing such mathematical extensions to Swift. HandySwift is only targeting to add the most common things that we think should be part of Swift in the first place. I don't think we should dive too much into such things and recommend other tools that are already amazing at such things instead. If you really wanted to add such things, please consider searching through the Swift Forums for existing suggestions or pitching your idea there and discussing a bit before making a bigger pull request here. For now, I consider this a non-bug. I'll reopen if necessary. |
I'm not quite sure what you mean by As a consequence, I cannot calculate the average of 2
Also, I think you quite misunderstood my intent – I just wanted to generalize the The natural consequence of generalising average calculation is a protocol providing the required basic arithmetic operations: addition and division. The implementation would be extremely minimal because all targeted Swift types already provide these functions. |
Ah yeah, sorry, I mixed things up with Okay, I'll reopen this. Could you please just post a PR with the approach you mean? I think then the discussion about the details of the implementation will be much easier. Currently, I'm not entirely sure what your suggested approach is. A PR would make that very clear. :) |
Yes, I'll drop a PR. Thank you very much for reconsidering :) |
Currently,
func average() -> Double
is defined as an extension onCollection where Element == Double
. What aboutCGFloat
s?I suggest to add a protocol
Field
(based on algebraic fields) providing addition, multiplication and division withSelf
elements, and also azero
andone
element. This would allow bothaverage()
andsum()
to be implemented more generically.Double
,Float
andCGFloat
could conform to this protocol (with nearly no additional implementation effort).The integer case would have to be treated specially though.
The text was updated successfully, but these errors were encountered: