We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
joined(separator:)
collapse
1 parent e89d138 commit 242817bCopy full SHA for 242817b
Sources/SwiftSyntaxMacroExpansion/MacroExpansion.swift
@@ -527,6 +527,14 @@ public func collapse<Node: SyntaxProtocol>(
527
default:
528
break
529
}
530
-
531
- return expansions.joined(separator: separator)
+ // Join the expansions with the given separator between them.
+ return expansions.reduce("") { (partialResult, expansion) in
532
+ // We don't add the separator before the first expansion or
533
+ // if the expansion already starts with the separator.
534
+ if (partialResult.isEmpty || expansion.hasPrefix(separator)) {
535
+ partialResult + expansion
536
+ } else {
537
+ partialResult + separator + expansion
538
+ }
539
540
0 commit comments