Skip to content

Commit b34dcbd

Browse files
author
mkandil
committed
Add filter method for ordered and unordered map
1 parent 9f225d6 commit b34dcbd

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

stdlib/public/Cxx/CxxDictionary.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,26 @@ public protocol CxxDictionary<Key, Value> {
4242
/// Do not implement this function manually in Swift.
4343
func __endUnsafe() -> RawIterator
4444

45+
<<<<<<< HEAD
4546
/// Do not implement this function manually in Swift.
4647
mutating func __endMutatingUnsafe() -> RawMutableIterator
48+
=======
49+
func filter(
50+
_ isIncluded: (Key, Value) throws -> Bool
51+
) rethrows -> [Key: Value] {
52+
var filteredDictionary: [Key: Value] = [:]
53+
let iterator = __findUnsafe(Key)
54+
let endIterator = __endUnsafe()
55+
56+
while iterator != endIterator {
57+
let pair = iterator.pointee
58+
if try isIncluded(pair.first, pair.second) {
59+
filteredDictionary[pair.first] = pair.second
60+
}
61+
iterator.successor()
62+
}
63+
}
64+
>>>>>>> 2dccec95be3 (Add filter method for ordered and unordered map)
4765
}
4866

4967
extension CxxDictionary {

0 commit comments

Comments
 (0)