Improve storage
This commit is contained in:
@ -8,4 +8,22 @@ extension Collection {
|
||||
}
|
||||
return sorted { conversion($0) < conversion($1) }
|
||||
}
|
||||
|
||||
func count(where predicate: (Element) throws -> Bool) rethrows -> Int {
|
||||
try reduce(0) { count, element in
|
||||
try predicate(element) ? count + 1 : count
|
||||
}
|
||||
}
|
||||
|
||||
func countThrows(where predicate: (Element) throws -> Void) -> Int {
|
||||
reduce(0) { count, element in
|
||||
do {
|
||||
try predicate(element)
|
||||
return count
|
||||
} catch {
|
||||
return count + 1
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user