@@ -95,6 +95,56 @@ public extension AsyncSequence {
95
95
func interspersed (every : Int = 1 , with separator : @Sendable @escaping () async -> Element ) -> AsyncInterspersedSequence<Self > {
96
96
AsyncInterspersedSequence (self , every : every, separator : separator)
97
97
}
98
+
99
+ /// Returns a new asynchronous sequence containing the elements of this asynchronous sequence, inserting
100
+ /// the given separator between each element.
101
+ ///
102
+ /// Any value of this asynchronous sequence's element type can be used as the separator.
103
+ ///
104
+ /// The following example shows how an async sequences of `String`s can be interspersed using `-` as the separator:
105
+ ///
106
+ /// ```
107
+ /// let input = ["A", "B", "C"].async
108
+ /// let interspersed = input.interspersed(with: "-")
109
+ /// for await element in interspersed {
110
+ /// print(element)
111
+ /// }
112
+ /// // Prints "A" "-" "B" "-" "C"
113
+ /// ```
114
+ ///
115
+ /// - Parameters:
116
+ /// - every: Dictates after how many elements a separator should be inserted.
117
+ /// - separator: A closure that produces the value to insert in between each of this async sequence’s elements.
118
+ /// - Returns: The interspersed asynchronous sequence of elements.
119
+ @inlinable
120
+ public func interspersed (every : Int = 1 , with separator : @Sendable @escaping () throws -> Element ) -> AsyncThrowingInterspersedSequence<Self > {
121
+ AsyncThrowingInterspersedSequence (self , every : every, separator : separator)
122
+ }
123
+
124
+ /// Returns a new asynchronous sequence containing the elements of this asynchronous sequence, inserting
125
+ /// the given separator between each element.
126
+ ///
127
+ /// Any value of this asynchronous sequence's element type can be used as the separator.
128
+ ///
129
+ /// The following example shows how an async sequences of `String`s can be interspersed using `-` as the separator:
130
+ ///
131
+ /// ```
132
+ /// let input = ["A", "B", "C"].async
133
+ /// let interspersed = input.interspersed(with: "-")
134
+ /// for await element in interspersed {
135
+ /// print(element)
136
+ /// }
137
+ /// // Prints "A" "-" "B" "-" "C"
138
+ /// ```
139
+ ///
140
+ /// - Parameters:
141
+ /// - every: Dictates after how many elements a separator should be inserted.
142
+ /// - separator: A closure that produces the value to insert in between each of this async sequence’s elements.
143
+ /// - Returns: The interspersed asynchronous sequence of elements.
144
+ @inlinable
145
+ public func interspersed (every : Int = 1 , with separator : @Sendable @escaping () async throws -> Element ) -> AsyncThrowingInterspersedSequence<Self > {
146
+ AsyncThrowingInterspersedSequence (self , every : every, separator : separator)
147
+ }
98
148
}
99
149
```
100
150
0 commit comments