@@ -57,7 +57,7 @@ extension MutableCollection where Self: BidirectionalCollection {
57
57
}
58
58
59
59
//===----------------------------------------------------------------------===//
60
- // rotate(at :) / rotate(subrange:at :)
60
+ // rotate(toStartAt :) / rotate(subrange:toStartAt :)
61
61
//===----------------------------------------------------------------------===//
62
62
63
63
extension MutableCollection {
@@ -101,7 +101,7 @@ extension MutableCollection {
101
101
@discardableResult
102
102
public mutating func rotate(
103
103
subrange: Range < Index > ,
104
- at newStart: Index
104
+ toStartAt newStart: Index
105
105
) -> Index {
106
106
var m = newStart, s = subrange. lowerBound
107
107
let e = subrange. upperBound
@@ -160,16 +160,16 @@ extension MutableCollection {
160
160
}
161
161
162
162
@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)
165
165
}
166
166
}
167
167
168
168
extension MutableCollection where Self: BidirectionalCollection {
169
169
@discardableResult
170
170
public mutating func rotate(
171
171
subrange: Range < Index > ,
172
- at newStart: Index
172
+ toStartAt newStart: Index
173
173
) -> Index {
174
174
reverse ( subrange: subrange. lowerBound..< newStart)
175
175
reverse ( subrange: newStart..< subrange. upperBound)
@@ -179,15 +179,15 @@ extension MutableCollection where Self: BidirectionalCollection {
179
179
}
180
180
181
181
/// 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.
183
183
///
184
184
/// Rotating a collection is equivalent to breaking the collection into two
185
185
/// sections at the index `newStart`, and then swapping those two sections.
186
186
/// In this example, the `numbers` array is rotated so that the element at
187
187
/// index `3` (`40`) is first:
188
188
///
189
189
/// var numbers = [10, 20, 30, 40, 50, 60, 70, 80]
190
- /// let oldStart = numbers.rotate(at : 3)
190
+ /// let oldStart = numbers.rotate(toStartAt : 3)
191
191
/// // numbers == [40, 50, 60, 70, 80, 10, 20, 30]
192
192
/// // numbers[oldStart] == 10
193
193
///
@@ -197,7 +197,26 @@ extension MutableCollection where Self: BidirectionalCollection {
197
197
///
198
198
/// - Complexity: O(*n*)
199
199
@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
200
219
public mutating func rotate( at newStart: Index ) -> Index {
201
- rotate ( subrange : startIndex ..< endIndex , at : newStart)
220
+ rotate ( toStartAt : newStart)
202
221
}
203
222
}
0 commit comments