From deac684aaa328a970493f4d932df8dcdfab7c73e Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 24 Oct 2022 20:52:43 -0700 Subject: [PATCH] Use for loop in capitalize implementation (#1377) --- src/function.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/function.rs b/src/function.rs index d2932f0..445adf1 100644 --- a/src/function.rs +++ b/src/function.rs @@ -81,18 +81,15 @@ fn arch(_context: &FunctionContext) -> Result { } fn capitalize(_context: &FunctionContext, s: &str) -> Result { - Ok( - s.chars() - .enumerate() - .flat_map(|(i, c)| { - if i == 0 { - c.to_uppercase().collect::>() - } else { - c.to_lowercase().collect::>() - } - }) - .collect(), - ) + let mut capitalized = String::new(); + for (i, c) in s.chars().enumerate() { + if i == 0 { + capitalized.extend(c.to_uppercase()); + } else { + capitalized.extend(c.to_lowercase()); + } + } + Ok(capitalized) } fn clean(_context: &FunctionContext, path: &str) -> Result {