Skip to content

Commit

Permalink
use fold()
Browse files Browse the repository at this point in the history
  • Loading branch information
rouzwelt committed Jan 9, 2025
1 parent 44f8a55 commit 1aec830
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions crates/cli-support/src/js/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,16 @@ impl<'a, 'b> Builder<'a, 'b> {
code.push('(');
if variadic {
if let Some((last, non_variadic_args)) = function_args.split_last() {
code.push_str(
&non_variadic_args
.iter()
.map(|v| v.name.as_str())
.collect::<Vec<_>>()
.join(", "),
);
code.push_str(&non_variadic_args.iter().enumerate().fold(
String::new(),
|acc, (i, v)| {
if i == 0 {
v.name.clone()
} else {
format!("{}, {}", acc, v.name.as_str())
}
},
));
if !non_variadic_args.is_empty() {
code.push_str(", ");
}
Expand All @@ -250,9 +253,14 @@ impl<'a, 'b> Builder<'a, 'b> {
code.push_str(
&function_args
.iter()
.map(|v| v.name.as_str())
.collect::<Vec<_>>()
.join(", "),
.enumerate()
.fold(String::new(), |acc, (i, v)| {
if i == 0 {
v.name.clone()
} else {
format!("{}, {}", acc, v.name.as_str())
}
}),
);
}
code.push_str(") {\n");
Expand Down

0 comments on commit 1aec830

Please sign in to comment.