Make code more functional by more function chaining.
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
d8a6e9ca9a
commit
07cbecc1ba
1 changed files with 32 additions and 34 deletions
|
@ -140,42 +140,40 @@ fn show(rt: &Runtime) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
for iter in iters {
|
Itertools::flatten(iters.into_iter())
|
||||||
let _ = iter
|
.into_get_iter(rt.store())
|
||||||
.into_get_iter(rt.store())
|
.trace_unwrap_exit(1)
|
||||||
.trace_unwrap_exit(1)
|
.filter_map(|opt| {
|
||||||
.filter_map(|opt| {
|
if opt.is_none() {
|
||||||
if opt.is_none() {
|
warn!("Failed to retrieve an entry from an existing store id");
|
||||||
warn!("Failed to retrieve an entry from an existing store id");
|
}
|
||||||
}
|
|
||||||
|
|
||||||
opt
|
opt
|
||||||
})
|
})
|
||||||
.filter(|e| e.is_log().map_err_trace_exit_unwrap(1))
|
.filter(|e| e.is_log().map_err_trace_exit_unwrap(1))
|
||||||
.map(|entry| (entry.diary_id().map_err_trace_exit_unwrap(1), entry))
|
.map(|entry| (entry.diary_id().map_err_trace_exit_unwrap(1), entry))
|
||||||
.sorted_by_key(|&(ref id, _)| id.clone())
|
.sorted_by_key(|tpl| tpl.0.clone())
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(id, entry)| {
|
.map(|tpl| { debug!("Found entry: {:?}", tpl.1); tpl })
|
||||||
debug!("Found entry: {:?}", entry);
|
.map(|(id, entry)| {
|
||||||
let _ = writeln!(rt.stdout(),
|
let _ = writeln!(rt.stdout(),
|
||||||
"{dname: >10} - {y: >4}-{m:0>2}-{d:0>2}T{H:0>2}:{M:0>2} - {text}",
|
"{dname: >10} - {y: >4}-{m:0>2}-{d:0>2}T{H:0>2}:{M:0>2} - {text}",
|
||||||
dname = id.diary_name(),
|
dname = id.diary_name(),
|
||||||
y = id.year(),
|
y = id.year(),
|
||||||
m = id.month(),
|
m = id.month(),
|
||||||
d = id.day(),
|
d = id.day(),
|
||||||
H = id.hour(),
|
H = id.hour(),
|
||||||
M = id.minute(),
|
M = id.minute(),
|
||||||
text = entry.get_content())
|
text = entry.get_content())
|
||||||
.to_exit_code()?;
|
.to_exit_code()?;
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt
|
||||||
.report_touched(entry.get_location())
|
.report_touched(entry.get_location())
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap(1);
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<()>, ExitCode>>()
|
.collect::<Result<Vec<()>, ExitCode>>()
|
||||||
.unwrap_or_exit();
|
.unwrap_or_exit();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_diary_name(rt: &Runtime) -> String {
|
fn get_diary_name(rt: &Runtime) -> String {
|
||||||
|
|
Loading…
Reference in a new issue