Skip to content

Instantly share code, notes, and snippets.

@jacobsapps
Created April 17, 2025 08:51
Show Gist options
  • Save jacobsapps/7cd65d194e170870d9a25c9770975c35 to your computer and use it in GitHub Desktop.
Save jacobsapps/7cd65d194e170870d9a25c9770975c35 to your computer and use it in GitHub Desktop.
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