Skip to content

Commit 4fe771d

Browse files
committed
Remove useless use of functional programming
1 parent 75ed7ae commit 4fe771d

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

src/commands.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -322,15 +322,12 @@ impl Commands {
322322
}
323323

324324
fn key_value_pair(s: &'static str) -> Option<&'static str> {
325-
s.match_indices("={}")
326-
.next()
327-
.map(|pair| {
328-
let name = &s[0..pair.0];
329-
if !name.is_empty() {
330-
Some(name)
331-
} else {
332-
None
333-
}
334-
})
335-
.flatten()
325+
let (match_index, _) = s.match_indices("={}").next()?;
326+
let name = &s[0..match_index];
327+
328+
if !name.is_empty() {
329+
Some(name)
330+
} else {
331+
None
332+
}
336333
}

src/main.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,12 @@ fn app() -> Result<(), Error> {
202202
}
203203

204204
fn main_menu(args: &Args, commands: &IndexMap<&str, (&str, GuardFn)>) -> String {
205-
let mut menu = commands.iter().fold(
206-
"Commands:\n".to_owned(),
207-
|mut menu, (base_cmd, (description, guard))| {
208-
if let Ok(true) = (guard)(&args) {
209-
menu += &format!("\t{cmd:<12}{desc}\n", cmd = base_cmd, desc = description);
210-
}
211-
menu
212-
},
213-
);
205+
let mut menu = "Commands:\n".to_owned();
206+
for (base_cmd, (description, guard)) in commands {
207+
if let Ok(true) = (guard)(&args) {
208+
menu += &format!("\t{cmd:<12}{desc}\n", cmd = base_cmd, desc = description);
209+
}
210+
}
214211

215212
menu += &format!("\t{help:<12}This menu\n", help = "?help");
216213
menu += "\nType ?help command for more info on a command.";

0 commit comments

Comments
 (0)