Skip to content

Instantly share code, notes, and snippets.

@Davichet-e
Created August 18, 2020 20:52
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
A small example of grouping-by crate.
// This returns for each year, the contract with the most days.
contracts.iter().grouping_by_max(
|contract| contract.date.year(), // Key of HashMap
|contract1, contract2| contract1.days.cmp(&contract2.days), // Comparator to get the max
) // Returns `HashMap<i32, Contract>`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment