@@ -566,6 +566,11 @@ extension Sequence where Iterator.Element == String {
566
566
/// in this sequence. The default separator is an empty string.
567
567
/// - Returns: A single, concatenated string.
568
568
public func joined( separator: String = " " ) -> String {
569
+ return _joined ( separator: separator)
570
+ }
571
+
572
+ @inline ( __always)
573
+ internal func _joined( separator: String = " " ) -> String {
569
574
var result = " "
570
575
571
576
// FIXME(performance): this code assumes UTF-16 in-memory representation.
@@ -607,6 +612,30 @@ extension Sequence where Iterator.Element == String {
607
612
}
608
613
}
609
614
615
+
616
+ // This overload is necessary because String now conforms to
617
+ // BidirectionalCollection, and there are other `joined` overloads that are
618
+ // considered more specific. See Flatten.swift.gyb.
619
+ extension BidirectionalCollection where Iterator. Element == String {
620
+ /// Returns a new string by concatenating the elements of the sequence,
621
+ /// adding the given separator between each element.
622
+ ///
623
+ /// The following example shows how an array of strings can be joined to a
624
+ /// single, comma-separated string:
625
+ ///
626
+ /// let cast = ["Vivien", "Marlon", "Kim", "Karl"]
627
+ /// let list = cast.joined(separator: ", ")
628
+ /// print(list)
629
+ /// // Prints "Vivien, Marlon, Kim, Karl"
630
+ ///
631
+ /// - Parameter separator: A string to insert between each of the elements
632
+ /// in this sequence. The default separator is an empty string.
633
+ /// - Returns: A single, concatenated string.
634
+ public func joined( separator: String = " " ) -> String {
635
+ return _joined ( separator: separator)
636
+ }
637
+ }
638
+
610
639
#if _runtime(_ObjC)
611
640
@_silgen_name ( " swift_stdlib_NSStringLowercaseString " )
612
641
func _stdlib_NSStringLowercaseString( _ str: AnyObject ) -> _CocoaString
0 commit comments