Created
April 17, 2025 08:51
-
-
Save jacobsapps/7cd65d194e170870d9a25c9770975c35 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
struct Counter: AsyncSequence { | |
typealias Element = Int | |
let howHigh: Int | |
struct AsyncIterator: AsyncIteratorProtocol { | |
let howHigh: Int | |
var current = 1 | |
mutating func next() async -> Int? { | |
guard current <= howHigh else { | |
return nil | |
} | |
let result = current | |
current += 1 | |
return result | |
} | |
} | |
func makeAsyncIterator() -> AsyncIterator { | |
return AsyncIterator(howHigh: howHigh) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment