Skip to content

max_by_key is wrong #558

Closed
Closed
@wagnerf42

Description

@wagnerf42

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions