@@ -57,7 +57,7 @@ extension MutableCollection where Self: BidirectionalCollection {
5757}
5858
5959//===----------------------------------------------------------------------===//
60- // rotate(at :) / rotate(subrange:at :)
60+ // rotate(toStartAt :) / rotate(subrange:toStartAt :)
6161//===----------------------------------------------------------------------===//
6262
6363extension MutableCollection {
@@ -101,7 +101,7 @@ extension MutableCollection {
101101 @discardableResult
102102 public mutating func rotate(
103103 subrange: Range < Index > ,
104- at newStart: Index
104+ toStartAt newStart: Index
105105 ) -> Index {
106106 var m = newStart, s = subrange. lowerBound
107107 let e = subrange. upperBound
@@ -160,16 +160,16 @@ extension MutableCollection {
160160 }
161161
162162 @discardableResult
163- public mutating func rotate( at newStart: Index ) -> Index {
164- rotate ( subrange: startIndex..< endIndex, at : newStart)
163+ public mutating func rotate( toStartAt newStart: Index ) -> Index {
164+ rotate ( subrange: startIndex..< endIndex, toStartAt : newStart)
165165 }
166166}
167167
168168extension MutableCollection where Self: BidirectionalCollection {
169169 @discardableResult
170170 public mutating func rotate(
171171 subrange: Range < Index > ,
172- at newStart: Index
172+ toStartAt newStart: Index
173173 ) -> Index {
174174 reverse ( subrange: subrange. lowerBound..< newStart)
175175 reverse ( subrange: newStart..< subrange. upperBound)
@@ -179,15 +179,15 @@ extension MutableCollection where Self: BidirectionalCollection {
179179 }
180180
181181 /// Rotates the elements of this collection so that the element
182- /// at the specified index moves to the front of the collection.
182+ /// at the specified index becomes the start of the collection.
183183 ///
184184 /// Rotating a collection is equivalent to breaking the collection into two
185185 /// sections at the index `newStart`, and then swapping those two sections.
186186 /// In this example, the `numbers` array is rotated so that the element at
187187 /// index `3` (`40`) is first:
188188 ///
189189 /// var numbers = [10, 20, 30, 40, 50, 60, 70, 80]
190- /// let oldStart = numbers.rotate(at : 3)
190+ /// let oldStart = numbers.rotate(toStartAt : 3)
191191 /// // numbers == [40, 50, 60, 70, 80, 10, 20, 30]
192192 /// // numbers[oldStart] == 10
193193 ///
@@ -197,7 +197,26 @@ extension MutableCollection where Self: BidirectionalCollection {
197197 ///
198198 /// - Complexity: O(*n*)
199199 @discardableResult
200+ public mutating func rotate( toStartAt newStart: Index ) -> Index {
201+ rotate ( subrange: startIndex..< endIndex, toStartAt: newStart)
202+ }
203+ }
204+
205+ // Deprecations
206+
207+ extension MutableCollection {
208+ @available ( * , deprecated, renamed: " rotate(subrange:toStartAt:) " )
209+ @discardableResult
210+ public mutating func rotate(
211+ subrange: Range < Index > ,
212+ at newStart: Index ) -> Index
213+ {
214+ rotate ( subrange: subrange, toStartAt: newStart)
215+ }
216+
217+ @available ( * , deprecated, renamed: " rotate(toStartAt:) " )
218+ @discardableResult
200219 public mutating func rotate( at newStart: Index ) -> Index {
201- rotate ( subrange : startIndex ..< endIndex , at : newStart)
220+ rotate ( toStartAt : newStart)
202221 }
203222}
0 commit comments