Skip to content

Commit 2be0ea4

Browse files
committed
Prevent infinite loop in filter
By being explicit about the expected return type, we ensure `Sequence.filter` is used. Otherwise `filter` ends up in an inifite loop.
1 parent 054e9ca commit 2be0ea4

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

Sources/SortedArray.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ extension SortedArray: RandomAccessCollection {
9999
}
100100

101101
public func filter(_ isIncluded: (Element) throws -> Bool) rethrows -> SortedArray<Element> {
102-
return SortedArray(sorted: try filter(isIncluded), areInIncreasingOrder: areInIncreasingOrder)
102+
let newElements: [Element] = try filter(isIncluded)
103+
return SortedArray(sorted: newElements, areInIncreasingOrder: areInIncreasingOrder)
103104
}
104105
}
105106

0 commit comments

Comments
 (0)