@@ -5,6 +5,19 @@ extension StringProtocol {
5
5
}
6
6
7
7
extension Sequence where Element == Text {
8
+
9
+ /// Returns a new `Text` by concatenating the elements of the sequence,
10
+ ///
11
+ /// The following example shows how an array of `Text` views can be joined to a
12
+ /// single `Text` view with comma-separated string:
13
+ ///
14
+ /// let cast = [Text("Vivien"), Text("Marlon"), Text("Kim")]
15
+ /// let list = cast.joined(separator: Text(", "))
16
+ /// // Gives Text("Vivien, Marlon, Kim")
17
+ ///
18
+ /// - Parameter separator: A `Text` view to insert between each of the elements
19
+ /// in this sequence. By default there is no separator.
20
+ /// - Returns: A single, concatenated `Text` view.
8
21
public func joined( separator: Text = Text ( " " ) ) -> Text {
9
22
var isInitial = true
10
23
return reduce ( Text ( " " ) ) { ( result, text) in
@@ -18,10 +31,24 @@ extension Sequence where Element == Text {
18
31
}
19
32
20
33
extension Text {
34
+
35
+ /// Creates a combined text view based on the given `content` by inserting
36
+ /// `separator` text views between each received text component.
37
+ ///
38
+ /// - Parameters:
39
+ /// - separator: The text to use as a separator between received text components.
40
+ /// By default there is no separator.
41
+ /// - content: A text builder that creates text components.
21
42
public init ( separator: Text = Text ( " " ) , @BasicTextBuilder content: ( ) -> [ Text ] ) {
22
43
self = content ( ) . joined ( separator: separator)
23
44
}
24
45
46
+ /// Creates a combined text view based on the given `content` by inserting
47
+ /// `separator` string between each received text component.
48
+ ///
49
+ /// - Parameters:
50
+ /// - separator: The string to use as a separator between received text components.
51
+ /// - content: A text builder that creates text components.
25
52
public init < Separator: StringProtocol > ( separator: Separator , @BasicTextBuilder content: ( ) -> [ Text ] ) {
26
53
self . init ( separator: Text ( separator) , content: content)
27
54
}
0 commit comments