summaryrefslogtreecommitdiffstats
path: root/bin/domain/imag-log/src/main.rs
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-11-07 13:39:47 +0100
committerMatthias Beyer <mail@beyermatthias.de>2018-11-07 13:51:28 +0100
commit07cbecc1baae777f4c00cf3c1e25a18fb2c0ff7b (patch)
treeb6026304d291c8c80ae759c87cbc66677163663a /bin/domain/imag-log/src/main.rs
parentd8a6e9ca9ae9ce92105b63c57d3a67088fc4cf7e (diff)
Make code more functional by more function chaining.
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'bin/domain/imag-log/src/main.rs')
-rw-r--r--bin/domain/imag-log/src/main.rs70
1 files changed, 34 insertions, 36 deletions
diff --git a/bin/domain/imag-log/src/main.rs b/bin/domain/imag-log/src/main.rs
index 5b6f01d2..5e09efce 100644
--- a/bin/domain/imag-log/src/main.rs
+++ b/bin/domain/imag-log/src/main.rs
@@ -140,42 +140,40 @@ fn show(rt: &Runtime) {
}
};
- for iter in iters {
- let _ = iter
- .into_get_iter(rt.store())
- .trace_unwrap_exit(1)
- .filter_map(|opt| {
- if opt.is_none() {
- warn!("Failed to retrieve an entry from an existing store id");
- }
-
- opt
- })
- .filter(|e| e.is_log().map_err_trace_exit_unwrap(1))
- .map(|entry| (entry.diary_id().map_err_trace_exit_unwrap(1), entry))
- .sorted_by_key(|&(ref id, _)| id.clone())
- .into_iter()
- .map(|(id, entry)| {
- debug!("Found entry: {:?}", entry);
- let _ = writeln!(rt.stdout(),
- "{dname: >10} - {y: >4}-{m:0>2}-{d:0>2}T{H:0>2}:{M:0>2} - {text}",
- dname = id.diary_name(),
- y = id.year(),
- m = id.month(),
- d = id.day(),
- H = id.hour(),
- M = id.minute(),
- text = entry.get_content())
- .to_exit_code()?;
-
- let _ = rt
- .report_touched(entry.get_location())
- .map_err_trace_exit_unwrap(1);
- Ok(())
- })
- .collect::<Result<Vec<()>, ExitCode>>()
- .unwrap_or_exit();
- }
+ Itertools::flatten(iters.into_iter())
+ .into_get_iter(rt.store())
+ .trace_unwrap_exit(1)
+ .filter_map(|opt| {
+ if opt.is_none() {
+ warn!("Failed to retrieve an entry from an existing store id");
+ }
+
+ opt
+ })
+ .filter(|e| e.is_log().map_err_trace_exit_unwrap(1))
+ .map(|entry| (entry.diary_id().map_err_trace_exit_unwrap(1), entry))
+ .sorted_by_key(|tpl| tpl.0.clone())
+ .into_iter()
+ .map(|tpl| { debug!("Found entry: {:?}", tpl.1); tpl })
+ .map(|(id, entry)| {
+ let _ = writeln!(rt.stdout(),
+ "{dname: >10} - {y: >4}-{m:0>2}-{d:0>2}T{H:0>2}:{M:0>2} - {text}",
+ dname = id.diary_name(),
+ y = id.year(),
+ m = id.month(),
+ d = id.day(),
+ H = id.hour(),
+ M = id.minute(),
+ text = entry.get_content())
+ .to_exit_code()?;
+
+ let _ = rt
+ .report_touched(entry.get_location())
+ .map_err_trace_exit_unwrap(1);
+ Ok(())
+ })
+ .collect::<Result<Vec<()>, ExitCode>>()
+ .unwrap_or_exit();
}
fn get_diary_name(rt: &Runtime) -> String {