summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-03-09 12:30:36 +0100
committerMatthias Beyer <mail@beyermatthias.de>2019-03-09 13:30:12 +0100
commitca2f130995b2669fa7878be7922364077e6a113a (patch)
tree3607c9f10e3e47f58803a3830dd0e4253ab0b266
parent205c2b09b6f79d1d770b5ee345002eecea8d54e9 (diff)
downloadimag-ca2f130995b2669fa7878be7922364077e6a113a.zip
imag-ca2f130995b2669fa7878be7922364077e6a113a.tar.gz
Rewrite: Diary::get_youngest_entry_id()
Rewrite to collect not so often internally. This removes one collect() from the implementation. One is still there in the sorted_by() call, though. Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--lib/domain/libimagdiary/src/diary.rs18
1 files changed, 4 insertions, 14 deletions
diff --git a/lib/domain/libimagdiary/src/diary.rs b/lib/domain/libimagdiary/src/diary.rs
index d8f0835..8d58c5a 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<Result<DiaryId>> {
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();