Skip to content

Commit

Permalink
Utilize transform instead of for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
tinder-cfuller committed Mar 15, 2024
1 parent 7f490da commit 992588b
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ public struct StateMachineHashableMacro: ExtensionMacro {
.map(\.name.text)
.map { "case .\($0):\nreturn .\($0)" }

var associatedValueCases: [String] = []
for element: EnumCaseElementSyntax in elements {
let associatedValueCases: [String] = elements.map { element in
if let parameters: EnumCaseParameterListSyntax = element.parameterClause?.parameters, !parameters.isEmpty {
if parameters.count > 1 {
let associatedValues: String = (1...parameters.count)
Expand All @@ -49,20 +48,20 @@ public struct StateMachineHashableMacro: ExtensionMacro {
case let .\(element.name.text)(\(associatedValues)):
return (\(associatedValues))
"""
associatedValueCases.append(`case`)
return `case`
} else {
let `case`: String = """
case let .\(element.name.text)(value):
return (value)
"""
associatedValueCases.append(`case`)
return `case`
}
} else {
let `case`: String = """
case .\(element.name.text):
return ()
"""
associatedValueCases.append(`case`)
return `case`
}
}

Expand Down

0 comments on commit 992588b

Please sign in to comment.