Skip to content

Commit

Permalink
chore: use vecmap over plain iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Jun 13, 2023
1 parent 8062ab5 commit fd7c241
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 26 deletions.
21 changes: 8 additions & 13 deletions crates/noirc_abi/src/input_parser/json.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{parse_str_to_field, InputValue};
use crate::{errors::InputParserError, Abi, AbiType, MAIN_RETURN_NAME};
use acvm::FieldElement;
use iter_extended::{btree_map, try_btree_map, try_vecmap};
use iter_extended::{btree_map, try_btree_map, try_vecmap, vecmap};
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;

Expand Down Expand Up @@ -74,18 +74,13 @@ impl From<InputValue> for JsonTypes {
let f_str = format!("0x{}", f.to_hex());
JsonTypes::String(f_str)
}
InputValue::Vec(v) => {
let array = v
.iter()
.map(|i| match i {
InputValue::Field(field) => {
JsonTypes::String(format!("0x{}", field.to_hex()))
}
_ => unreachable!(
"Only arrays of simple field elements are allowable currently"
),
})
.collect();
InputValue::Vec(vector) => {
let array = vecmap(vector, |i| match i {
InputValue::Field(field) => JsonTypes::String(format!("0x{}", field.to_hex())),
_ => {
unreachable!("Only arrays of simple field elements are allowable currently")
}
});
JsonTypes::Array(array)
}
InputValue::String(s) => JsonTypes::String(s),
Expand Down
21 changes: 8 additions & 13 deletions crates/noirc_abi/src/input_parser/toml.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{parse_str_to_field, InputValue};
use crate::{errors::InputParserError, Abi, AbiType, MAIN_RETURN_NAME};
use acvm::FieldElement;
use iter_extended::{btree_map, try_btree_map, try_vecmap};
use iter_extended::{btree_map, try_btree_map, try_vecmap, vecmap};
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;

Expand Down Expand Up @@ -71,18 +71,13 @@ impl From<InputValue> for TomlTypes {
let f_str = format!("0x{}", f.to_hex());
TomlTypes::String(f_str)
}
InputValue::Vec(v) => {
let array = v
.iter()
.map(|i| match i {
InputValue::Field(field) => {
TomlTypes::String(format!("0x{}", field.to_hex()))
}
_ => unreachable!(
"Only arrays of simple field elements are allowable currently"
),
})
.collect();
InputValue::Vec(vector) => {
let array = vecmap(vector, |i| match i {
InputValue::Field(field) => TomlTypes::String(format!("0x{}", field.to_hex())),
_ => {
unreachable!("Only arrays of simple field elements are allowable currently")
}
});
TomlTypes::Array(array)
}
InputValue::String(s) => TomlTypes::String(s),
Expand Down

0 comments on commit fd7c241

Please sign in to comment.