diff --git a/lib/domain/libimagdiary/src/diary.rs b/lib/domain/libimagdiary/src/diary.rs index d8f08352..8d58c5a1 100644 --- a/lib/domain/libimagdiary/src/diary.rs +++ b/lib/domain/libimagdiary/src/diary.rs @@ -99,24 +99,14 @@ impl Diary for Store { } /// get the id of the youngest entry - /// - /// TODO: We collect internally here. We shouldn't do that. Solution unclear. fn get_youngest_entry_id(&self, diary_name: &str) -> Option> { match Diary::entries(self, diary_name) { Err(e) => Some(Err(e)), Ok(entries) => { - let mut sorted_entries = vec![]; - - for entry in entries { - let entry = match entry { - Ok(e) => DiaryId::from_storeid(&e), - Err(e) => return Some(Err(e)), - }; - - sorted_entries.push(entry); - } - - sorted_entries.into_iter().sorted_by(|a, b| { + entries.map(|ent| { + ent.and_then(|id| DiaryId::from_storeid(&id)) + }) + .sorted_by(|a, b| { match (a, b) { (&Ok(ref a), &Ok(ref b)) => { let a : NaiveDateTime = a.clone().into();