Use for loop in capitalize implementation (#1377)

This commit is contained in:
Casey Rodarmor 2022-10-24 20:52:43 -07:00 committed by GitHub
parent aaef61b908
commit deac684aaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -81,18 +81,15 @@ fn arch(_context: &FunctionContext) -> Result<String, String> {
} }
fn capitalize(_context: &FunctionContext, s: &str) -> Result<String, String> { fn capitalize(_context: &FunctionContext, s: &str) -> Result<String, String> {
Ok( let mut capitalized = String::new();
s.chars() for (i, c) in s.chars().enumerate() {
.enumerate()
.flat_map(|(i, c)| {
if i == 0 { if i == 0 {
c.to_uppercase().collect::<Vec<_>>() capitalized.extend(c.to_uppercase());
} else { } else {
c.to_lowercase().collect::<Vec<_>>() capitalized.extend(c.to_lowercase());
} }
}) }
.collect(), Ok(capitalized)
)
} }
fn clean(_context: &FunctionContext, path: &str) -> Result<String, String> { fn clean(_context: &FunctionContext, path: &str) -> Result<String, String> {