Skip to content
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

Allow mean on both f32 and &f32 #122

Closed

Conversation

TheNeikos
Copy link

@TheNeikos TheNeikos commented Nov 14, 2024

The two patches are somewhat independent. The first is the 'minimal' change to allow using a Iterator<Item = &f32>`. The second is a more complete implementation, inspired by the constructs used in the standard library.

Feel free to pick either!

Fixes #121


Hm, I just realized that micromath is in 2.1 🥲 so this would not fly for a minor/patch release.

If you don't plan on releasing 3.x, it can't be implemented AFAIK. Since Mean takes no arguments, there's only ever a single instance of it and as such can't be implemented for differing I

Signed-off-by: Marcel Müller <neikos@neikos.email>
Since each trait 'instance' can only be implemented once for each type,
we could not implement `Mean` for both `I: Iterator<Item = f32>` and
`Item = &f32`, as the `I` could technically be the same.

This patch rewrites it to instead of taking an Input type parameter to
differentiate the traits, and takes an approach similar to `Sum` in the
standard library.

It also has the advantage that users could extend what can be taken a
'mean' of by implementing `Mean` themselves.

Technically, this could be made a generic impl for types that implement
a certain set of traits (sum + div), but that is potentially not super
useful and just makes things more complicated.

Signed-off-by: Marcel Müller <neikos@neikos.email>
@tarcieri
Copy link
Owner

Yeah, as you noted this is a breaking change which we're probably not ready to make at this point

@TheNeikos TheNeikos closed this Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Impl Mean for Iterator<Item = &f32> as well?
2 participants