Skip to content

Commit 5921620

Browse files
add reverse implementation (#276)
1 parent 281b07a commit 5921620

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Sources/ComposableArchitecture/SwiftUI/IdentifiedArray.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ where ID: Hashable {
199199
var rng = SystemRandomNumberGenerator()
200200
self.shuffle(using: &rng)
201201
}
202+
203+
public mutating func reverse() {
204+
ids.reverse()
205+
}
202206
}
203207

204208
extension IdentifiedArray: CustomDebugStringConvertible {

Tests/ComposableArchitectureTests/IdentifiedArrayTests.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,22 @@ final class IdentifiedArrayTests: XCTestCase {
227227
XCTAssertEqual([1, 3, 5, 4, 2], array.ids)
228228
}
229229
#endif
230+
231+
func testReverse() {
232+
var array: IdentifiedArray = [
233+
ComparableValue(id: 1, value: 100),
234+
ComparableValue(id: 2, value: 50),
235+
ComparableValue(id: 3, value: 75),
236+
]
237+
238+
array.reverse()
239+
240+
XCTAssertEqual([3, 2, 1], array.ids)
241+
XCTAssertEqual(
242+
[
243+
ComparableValue(id: 3, value: 75),
244+
ComparableValue(id: 2, value: 50),
245+
ComparableValue(id: 1, value: 100),
246+
], array)
247+
}
230248
}

0 commit comments

Comments
 (0)