Skip to content

Instantly share code, notes, and snippets.

@Davichet-e

Davichet-e/grouping-by.rs Secret

Created Aug 18, 2020
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