Created
November 29, 2024 19:22
-
-
Save robertmryan/aa279babad83d30ec6ed5a0d49f92023 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alternatively, see https://gist.github.com/robertmryan/3127092969b144335ae9f5186d7d97fc.