@@ -233,16 +233,24 @@ extension BidirectionalCollection where Element: Equatable {
233
233
// MARK: Fixed pattern algorithms
234
234
235
235
extension Collection where Element: Equatable {
236
- // FIXME: Replace `SplitCollection` when SE-0346 is enabled
236
+ @_disfavoredOverload
237
+ func split< S: Sequence > (
238
+ by separator: S
239
+ ) -> SplitCollection < ZSearcher < Self > > where S. Element == Element {
240
+ split ( by: ZSearcher ( pattern: Array ( separator) , by: == ) )
241
+ }
242
+
243
+ // FIXME: Return `some Collection<SubSequence>` for SE-0346
237
244
/// Returns the longest possible subsequences of the collection, in order,
238
245
/// around elements equal to the given separator.
239
246
/// - Parameter separator: The element to be split upon.
240
247
/// - Returns: A collection of subsequences, split from this collection's
241
248
/// elements.
242
- func split< S: Sequence > (
249
+ @available ( SwiftStdlib 5 . 7 , * )
250
+ public func split< S: Sequence > (
243
251
by separator: S
244
- ) -> SplitCollection < ZSearcher < Self > > where S. Element == Element {
245
- split ( by: ZSearcher ( pattern: Array ( separator) , by: == ) )
252
+ ) -> [ SubSequence ] where S. Element == Element {
253
+ Array ( split ( by: ZSearcher ( pattern: Array ( separator) , by: == ) ) )
246
254
}
247
255
}
248
256
@@ -282,12 +290,7 @@ extension BidirectionalCollection where Element: Comparable {
282
290
283
291
@available ( SwiftStdlib 5 . 7 , * )
284
292
extension BidirectionalCollection where SubSequence == Substring {
285
- // FIXME: Replace `SplitCollection` when SE-0346 is enabled
286
- /// Returns the longest possible subsequences of the collection, in order,
287
- /// around elements equal to the given separator.
288
- /// - Parameter separator: A regex describing elements to be split upon.
289
- /// - Returns: A collection of substrings, split from this collection's
290
- /// elements.
293
+ @_disfavoredOverload
291
294
func split< R: RegexComponent > (
292
295
by separator: R
293
296
) -> SplitCollection < RegexConsumer < R , Self > > {
@@ -299,4 +302,16 @@ extension BidirectionalCollection where SubSequence == Substring {
299
302
) -> ReversedSplitCollection < RegexConsumer < R , Self > > {
300
303
splitFromBack ( by: RegexConsumer ( separator) )
301
304
}
305
+
306
+ // FIXME: Return `some Collection<Substring>` for SE-0346
307
+ /// Returns the longest possible subsequences of the collection, in order,
308
+ /// around elements equal to the given separator.
309
+ /// - Parameter separator: A regex describing elements to be split upon.
310
+ /// - Returns: A collection of substrings, split from this collection's
311
+ /// elements.
312
+ public func split< R: RegexComponent > (
313
+ by separator: R
314
+ ) -> [ SubSequence ] {
315
+ Array ( split ( by: RegexConsumer ( separator) ) )
316
+ }
302
317
}
0 commit comments