Make code more functional by more function chaining.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2018-11-07 13:39:47 +01:00
parent d8a6e9ca9a
commit 07cbecc1ba

View file

@ -140,8 +140,7 @@ 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| {
@ -153,10 +152,10 @@ fn show(rt: &Runtime) {
}) })
.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(|tpl| { debug!("Found entry: {:?}", tpl.1); tpl })
.map(|(id, entry)| { .map(|(id, entry)| {
debug!("Found entry: {:?}", 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(),
@ -176,7 +175,6 @@ fn show(rt: &Runtime) {
.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 {
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadExt;