summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRyan Geary <rtgnj42@gmail.com>2019-09-11 11:52:14 -0400
committerRyan Geary <rtgnj42@gmail.com>2019-09-11 11:52:20 -0400
commit5a5a77e88fd78e1a301f30f295e8fab7912ce12a (patch)
tree67432a82b3de781e1d6c2e37e651ccdfde3bc107 /src
parent18dcf845fbce884a12ab64a9de048b766e7556f7 (diff)
Unify enumerating lines in print_choice
Diffstat (limited to 'src')
-rw-r--r--src/main.rs22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/main.rs b/src/main.rs
index 68ff3cb..60d769e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -16,21 +16,23 @@ enum Choice {
impl Choice {
fn print_choice(&self, line: &String, opt: &Opt) {
- let words: Vec<&str> = line.split_whitespace().collect();
+ let words = line.split_whitespace().into_iter().enumerate();
match self {
Choice::Field(i) => {
- if *i < words.len().try_into().unwrap() {
- print!("{} ", words[*i as usize]);
- }
- },
+ print!(
+ "{} ",
+ words
+ .filter(|x| x.0 == *i as usize)
+ .map(|x| x.1)
+ .collect::<String>()
+ );
+ }
Choice::FieldRange(r) => match r {
- (None, None) => print!("{}", words.into_iter().collect::<String>()),
+ (None, None) => print!("{}", words.map(|x| x.1).collect::<String>()),
(Some(start), None) => print!(
"{} ",
words
- .into_iter()
- .enumerate()
.filter(|x| x.0 >= (*start).try_into().unwrap())
.map(|x| x.1)
.collect::<Vec<&str>>()
@@ -45,8 +47,6 @@ impl Choice {
print!(
"{} ",
words
- .into_iter()
- .enumerate()
.filter(|x| x.0 < e)
.map(|x| x.1)
.collect::<Vec<&str>>()
@@ -62,8 +62,6 @@ impl Choice {
print!(
"{} ",
words
- .into_iter()
- .enumerate()
.filter(|x| x.0 < e && x.0 >= (*start).try_into().unwrap())
.map(|x| x.1)
.collect::<Vec<&str>>()