Skip to content

Instantly share code, notes, and snippets.

@robertmryan
Created November 29, 2024 19:22
Show Gist options
  • Save robertmryan/aa279babad83d30ec6ed5a0d49f92023 to your computer and use it in GitHub Desktop.
Save robertmryan/aa279babad83d30ec6ed5a0d49f92023 to your computer and use it in GitHub Desktop.
extension Sequence {
func first(where predicate: sending (Self.Element) async throws -> Bool) async rethrows -> Self.Element? {
for element in self {
if try await predicate(element) {
return element
}
}
return nil
}
}
func getCounter4(number: Int) async -> Counter? {
await counters.first { counter in
await counter.number == number
}
}
@robertmryan
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment