Skip to content

sort_by takes a comparison fn, but min_by/max_by take a "scoring" fn #15311

Closed
@ben0x539

Description

@ben0x539

This is sorta inconsistent :(

fn sort_by(self, compare: |&T, &T| -> Ordering)

fn max_by<B: Ord>(&mut self, f: |&A| -> B) -> Option<A>

Having a comparison function is kinda more useful because then you could use min_by/max_by with non-total Ord types more easily, but it's also a bit more effort in the easy case. I dunno. fwiw, ruby's sort_by takes a "scoring"-like block and haskell's sortBy takes a comparison function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions