Skip to content

max_by_key is wrong #558

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

Closed
wagnerf42 opened this issue Nov 19, 2019 · 1 comment · Fixed by #559
Closed

max_by_key is wrong #558

wagnerf42 opened this issue Nov 19, 2019 · 1 comment · Fixed by #559

Comments

@wagnerf42
Copy link

hi, it seems to me that max_by_key is wrong.
i'm not 100% sure since I just started playing with futures and the error messages are kind of harsher than I'm used to.

the doc seems wrong to me :

let s = stream::from_iter(vec![-1isize, -2, -3]);

let max = s.clone().max_by_key(|x| x.abs()).await;
assert_eq!(max, Some(3));

I would expect a max of -3 and not 3.
also in the source code, the MaxByKeyFuture has a key_by fn which returns a S::Item and not a B

@yoshuawuyts
Copy link
Contributor

@wagnerf42 You're indeed correct, thanks for reporting. We've merged the patch in #559 and this should be fixed in the next release. Thanks heaps!

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 a pull request may close this issue.

2 participants