diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2019-10-16 19:13:16 +0200 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2019-10-16 19:13:16 +0200 |
commit | 7331909e7767509b27877d99adff1de44b41f8fb (patch) | |
tree | f80778d8bbe539d9670a4cb98426ebf69b03bec1 | |
parent | 0f326725722743a4a003f1125c82f12787272bf8 (diff) | |
download | frotate.rs-7331909e7767509b27877d99adff1de44b41f8fb.tar.gz |
Reverse date partitions later
Make partition_days() more like partition().
-rw-r--r-- | src/lib.rs | 5 | ||||
-rw-r--r-- | src/main.rs | 7 |
2 files changed, 8 insertions, 4 deletions
@@ -87,8 +87,8 @@ mod tests { d(2019, 09, 01), d(2019, 09, 02), d(2019, 09, 03), d(2019, 09, 04)]; let outs = list![list![d(2019, 09, 04)], - list![d(2019, 09, 02), d(2019, 09, 03)], - list![d(2019, 08, 30), d(2019, 08, 31), d(2019, 09, 01)]]; + list![d(2019, 09, 03), d(2019, 09, 02)], + list![d(2019, 09, 01), d(2019, 08, 31), d(2019, 08, 30)]]; assert_eq!(partition_days(&exp2, &ins), outs); } @@ -138,7 +138,6 @@ pub fn partition_days( .map(|l| { l.into_iter() .map(|d| day1 - Duration::days(d)) - .rev() .collect() }) .collect(); diff --git a/src/main.rs b/src/main.rs index 752204c..781018f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ use std::process::exit; use chrono::NaiveDate; use docopt::Docopt; use serde::Deserialize; +use std::collections::LinkedList; mod lib; use lib::partition_days; @@ -40,7 +41,11 @@ fn main() { .and_then(|d| d.deserialize()) .unwrap_or_else(|e| e.exit()); - let parts = partition_days(&|n| exponent(args.flag_base, n), &args.arg_day); + let parts: LinkedList<LinkedList<NaiveDate>> = + partition_days(&|n| exponent(args.flag_base, n), &args.arg_day) + .into_iter() + .map(|l| l.into_iter().rev().collect()) + .collect(); if args.flag_keep { for days in parts.iter() { |