Sort albums by month if two releases of the same artist happen in the same year #155

Merged
Showing only changes of commit 0fee810040 - Show all commits

View File

@ -86,17 +86,19 @@ pub trait WithId {
fn id(&self) -> &Self::Id; fn id(&self) -> &Self::Id;
} }
pub struct MergeCollections<ID, T> { pub struct MergeCollections<ID, T, IT> {
_id: PhantomData<ID>, _id: PhantomData<ID>,
_t: PhantomData<T>, _t: PhantomData<T>,
_it: PhantomData<IT>,
} }
impl<ID, T> MergeCollections<ID, T> impl<ID, T, IT> MergeCollections<ID, T, IT>
where where
ID: Eq + Hash + Clone, ID: Eq + Hash + Clone,
T: WithId<Id = ID> + Merge + Ord, T: WithId<Id = ID> + Merge + Ord,
IT: IntoIterator<Item = T>,
{ {
pub fn merge_iter<IT: IntoIterator<Item = T>>(primary: IT, secondary: IT) -> Vec<T> { pub fn merge_iter(primary: IT, secondary: IT) -> Vec<T> {
let primary = primary let primary = primary
.into_iter() .into_iter()
.map(|item| (item.id().clone(), item)) .map(|item| (item.id().clone(), item))
@ -104,7 +106,7 @@ where
Self::merge(primary, secondary) Self::merge(primary, secondary)
} }
pub fn merge<IT: IntoIterator<Item = T>>(mut primary: HashMap<ID, T>, secondary: IT) -> Vec<T> { pub fn merge(mut primary: HashMap<ID, T>, secondary: IT) -> Vec<T> {
for secondary_item in secondary { for secondary_item in secondary {
if let Some(ref mut primary_item) = primary.get_mut(secondary_item.id()) { if let Some(ref mut primary_item) = primary.get_mut(secondary_item.id()) {
primary_item.merge_in_place(secondary_item); primary_item.merge_in_place(secondary_item);