Skip to content

Commit 5ef9b47

Browse files
jeffersonsetiawanmluisbrown
authored andcommitted
add reverse implementation (#276)
1 parent d228601 commit 5ef9b47

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
@@ -200,6 +200,10 @@ where ID: Hashable {
200200
var rng = SystemRandomNumberGenerator()
201201
self.shuffle(using: &rng)
202202
}
203+
204+
public mutating func reverse() {
205+
ids.reverse()
206+
}
203207
}
204208

205209
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)

Tests/ComposableArchitectureTests/IdentifiedArrayTests.swift

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

0 commit comments

Comments
 (0)