Skip to content

Commit

Permalink
add vecmap
Browse files Browse the repository at this point in the history
  • Loading branch information
jonybur committed Oct 11, 2023
1 parent 08a0d88 commit 9688f9f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tooling/nargo_fmt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ bytecount = "0.6.3"
noirc_frontend.workspace = true
serde.workspace = true
toml.workspace = true
iter-extended.workspace = true
thiserror.workspace = true

[dev-dependencies]
Expand Down
26 changes: 17 additions & 9 deletions tooling/nargo_fmt/src/visitor/expr.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use iter_extended::vecmap;
use noirc_frontend::{
hir::resolution::errors::Span, ArrayLiteral, BlockExpression, Expression, ExpressionKind,
Literal, Statement,
Expand Down Expand Up @@ -26,15 +27,22 @@ impl FmtVisitor<'_> {
visitor.buffer
}
ExpressionKind::Lambda(lambda) => {
let formatted_params = lambda
.parameters
.iter()
.map(|(pattern, unresolved_type)| format!("{}: {}", pattern, unresolved_type))
.collect::<Vec<_>>()
.join(", ");
let formatted_body = self.format_expr(lambda.body.clone());
format!("|{}| -> {}", formatted_params, formatted_body)
}
let formatted_params = vecmap(&lambda.parameters, |(pattern, unresolved_type)| {
// Convert to string and then trim
let pattern_str = pattern.to_string();
let pattern_str = pattern_str.trim().to_string();

let type_str = unresolved_type.to_string();
let type_str = type_str.trim().to_string();

format!("{}: {}", pattern_str, type_str)
}).join(", ");

let formatted_body_str = self.format_expr(lambda.body.clone());
let formatted_body = formatted_body_str.trim().to_string();

format!("|{}| {}", formatted_params, formatted_body)
}
ExpressionKind::Prefix(prefix) => {
format!("{}{}", prefix.operator, self.format_expr(prefix.rhs))
}
Expand Down

0 comments on commit 9688f9f

Please sign in to comment.