Skip to content

Commit

Permalink
refactor: use forEach instead of map in relevant places
Browse files Browse the repository at this point in the history
  • Loading branch information
kashif-m committed Jul 23, 2024
1 parent 6ecf4ff commit e615538
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/PaymentMethodCollectElement.res
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let make = (~integrateError, ~logger) => {
React.useEffect(() => {
let availablePM: array<paymentMethod> = []
let availablePMT: array<paymentMethodType> = []
let _ = options.enabledPaymentMethods->Array.map(pm => {
options.enabledPaymentMethods->Array.forEach(pm => {
switch pm {
| Card(_) =>
if !(availablePM->Array.includes(Card)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Types/PaymentMethodCollectTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ let decodePaymentMethodType = (json: JSON.t): option<array<paymentMethodType>> =
->Dict.get("payment_method_types")
->Option.flatMap(JSON.Decode.array)
->Option.flatMap(pmts => {
let _ = pmts->Array.map(pmt => {
pmts->Array.forEach(pmt => {
let payment_method_type = pmt->JSON.Decode.string
let _ = switch (payment_method, payment_method_type) {
switch (payment_method, payment_method_type) {
| (Some("card"), Some(cardType)) =>
switch decodeCard(cardType) {
| Some(card) => payment_methods->Array.push(Card(card))
Expand Down
19 changes: 9 additions & 10 deletions src/Utilities/PaymentMethodCollectUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,8 @@ let formPaymentMethodData = (
| false => None
| true =>
let pmd = [(ACHRoutingNumber, routingNumber), (ACHAccountNumber, accountNumber)]
let _ = bankName->Option.map(bankName => pmd->Array.push((ACHBankName, bankName)))
let _ = city->Option.map(city => pmd->Array.push((ACHBankCity, city)))
bankName->Option.forEach(bankName => pmd->Array.push((ACHBankName, bankName)))
city->Option.forEach(city => pmd->Array.push((ACHBankCity, city)))
Some(BankTransfer, BankTransfer(ACH), pmd)
}
| _ => None
Expand All @@ -603,8 +603,8 @@ let formPaymentMethodData = (
| false => None
| true =>
let pmd = [(BacsSortCode, sortCode), (BacsAccountNumber, accountNumber)]
let _ = bankName->Option.map(bankName => pmd->Array.push((BacsBankName, bankName)))
let _ = city->Option.map(city => pmd->Array.push((BacsBankCity, city)))
bankName->Option.forEach(bankName => pmd->Array.push((BacsBankName, bankName)))
city->Option.forEach(city => pmd->Array.push((BacsBankCity, city)))
Some(BankTransfer, BankTransfer(Bacs), pmd)
}
| _ => None
Expand All @@ -630,11 +630,10 @@ let formPaymentMethodData = (
| false => None
| true =>
let pmd = [(SepaIban, iban)]
let _ = bic->Option.map(bic => pmd->Array.push((SepaBic, bic)))
let _ = bankName->Option.map(bankName => pmd->Array.push((SepaBankName, bankName)))
let _ = city->Option.map(city => pmd->Array.push((SepaBankCity, city)))
let _ =
countryCode->Option.map(countryCode => pmd->Array.push((SepaCountryCode, countryCode)))
bic->Option.forEach(bic => pmd->Array.push((SepaBic, bic)))
bankName->Option.forEach(bankName => pmd->Array.push((SepaBankName, bankName)))
city->Option.forEach(city => pmd->Array.push((SepaBankCity, city)))
countryCode->Option.forEach(countryCode => pmd->Array.push((SepaCountryCode, countryCode)))
Some(BankTransfer, BankTransfer(Sepa), pmd)
}
| _ => None
Expand All @@ -656,7 +655,7 @@ let formBody = (flow: paymentMethodCollectFlow, paymentMethodData: paymentMethod
let (paymentMethod, paymentMethodType, fields) = paymentMethodData
let pmdApiFields = []

let _ = fields->Array.map(field => {
fields->Array.forEach(field => {
let (key, value) = field
switch key {
// Card
Expand Down
6 changes: 2 additions & 4 deletions src/Utilities/Utils.res
Original file line number Diff line number Diff line change
Expand Up @@ -1095,8 +1095,7 @@ let rec flatten = (obj, addIndicatorForObject) => {
let arrayArray = []
dictArray->Array.forEachWithIndex((item, index) => {
switch item->JSON.Classify.classify {
| String(_str) =>
let _ = stringArray->Array.push(item)
| String(_str) => stringArray->Array.push(item)
| Object(_obj) => {
let flattenedSubObj = flatten(item, addIndicatorForObject)
flattenedSubObj
Expand All @@ -1109,8 +1108,7 @@ let rec flatten = (obj, addIndicatorForObject) => {
)
}

| _ =>
let _ = arrayArray->Array.push(item)
| _ => arrayArray->Array.push(item)
}
})
if stringArray->Array.length > 0 {
Expand Down

0 comments on commit e615538

Please sign in to comment.