Skip to content

Commit f0511e9

Browse files
committed
Merge branch 'master' of github.com:ole/SortedArray
2 parents 784741b + c7ea3d7 commit f0511e9

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

Sources/SortedArray.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ extension SortedArray: RandomAccessCollection {
9797
public subscript(position: Index) -> Element {
9898
return _elements[position]
9999
}
100+
101+
public func filter(_ isIncluded: (Element) throws -> Bool) rethrows -> SortedArray<Element> {
102+
let newElements: [Element] = try filter(isIncluded)
103+
return SortedArray(sorted: newElements, areInIncreasingOrder: areInIncreasingOrder)
104+
}
100105
}
101106

102107
extension SortedArray: CustomStringConvertible, CustomDebugStringConvertible {

Tests/SortedArrayTests/SortedArrayTests.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ class SortedArrayTests: XCTestCase {
151151
let description = String(reflecting: sut)
152152
XCTAssertEqual(description, "<SortedArray> [\"a\", \"b\", \"c\"]")
153153
}
154+
155+
func testFilter() {
156+
let sut = SortedArray(unsorted: ["a", "b", "c"])
157+
assertElementsEqual(sut.filter { $0 != "a" }, ["b", "c"])
158+
}
154159
}
155160

156161
extension SortedArrayTests {
@@ -178,7 +183,8 @@ extension SortedArrayTests {
178183
("testMin", testMin),
179184
("testMax", testMax),
180185
("testCustomStringConvertible", testCustomStringConvertible),
181-
("testCustomDebugStringConvertible", testCustomDebugStringConvertible)
186+
("testCustomDebugStringConvertible", testCustomDebugStringConvertible),
187+
("testFilter", testFilter),
182188
]
183189
}
184190
}

0 commit comments

Comments
 (0)