@@ -209,70 +209,6 @@ extension BidirectionalCollection where Element: Equatable {
209209 }
210210}
211211
212- //===----------------------------------------------------------------------===//
213- // subranges(where:) / subranges(of:)
214- //===----------------------------------------------------------------------===//
215-
216- extension Collection {
217- /// Returns the indices of all the elements that match the given predicate.
218- ///
219- /// For example, you can use this method to find all the places that a
220- /// vowel occurs in a string.
221- ///
222- /// let str = "Fresh cheese in a breeze"
223- /// let vowels: Set<Character> = ["a", "e", "i", "o", "u"]
224- /// let allTheVowels = str.subranges(where: { vowels.contains($0) })
225- /// // str[allTheVowels].count == 9
226- ///
227- /// - Parameter predicate: A closure that takes an element as its argument
228- /// and returns a Boolean value that indicates whether the passed element
229- /// represents a match.
230- /// - Returns: A set of the indices of the elements for which `predicate`
231- /// returns `true`.
232- ///
233- /// - Complexity: O(*n*), where *n* is the length of the collection.
234- @available ( macOS 9999 , iOS 9999 , watchOS 9999 , tvOS 9999 , * )
235- public func subranges( where predicate: ( Element ) throws -> Bool ) rethrows
236- -> RangeSet < Index >
237- {
238- if isEmpty { return RangeSet ( ) }
239-
240- var result = RangeSet < Index > ( )
241- var i = startIndex
242- while i != endIndex {
243- let next = index ( after: i)
244- if try predicate ( self [ i] ) {
245- result. _append ( i..< next)
246- }
247- i = next
248- }
249-
250- return result
251- }
252- }
253-
254- extension Collection where Element: Equatable {
255- /// Returns the indices of all the elements that are equal to the given
256- /// element.
257- ///
258- /// For example, you can use this method to find all the places that a
259- /// particular letter occurs in a string.
260- ///
261- /// let str = "Fresh cheese in a breeze"
262- /// let allTheEs = str.subranges(of: "e")
263- /// // str[allTheEs].count == 7
264- ///
265- /// - Parameter element: An element to look for in the collection.
266- /// - Returns: A set of the indices of the elements that are equal to
267- /// `element`.
268- ///
269- /// - Complexity: O(*n*), where *n* is the length of the collection.
270- @available ( macOS 9999 , iOS 9999 , watchOS 9999 , tvOS 9999 , * )
271- public func subranges( of element: Element ) -> RangeSet < Index > {
272- subranges ( where: { $0 == element } )
273- }
274- }
275-
276212//===----------------------------------------------------------------------===//
277213// partition(by:)
278214//===----------------------------------------------------------------------===//
0 commit comments