Skip to content

Instantly share code, notes, and snippets.

Avatar
🔥
#StandWithUkraine

Max Desiatov MaxDesiatov

🔥
#StandWithUkraine
View GitHub Profile
@MaxDesiatov
MaxDesiatov / swift-generators.md
Last active Sep 12, 2018
Pitch for generator syntax in Swift
View swift-generators.md

Pitch for generators, coroutines and a smooth path to async/await in Swift

Generator use case: streams

Streams in programming is an important concept. It allows you to handle high volumes of data without consuming much memory. A stream is an object that holds internal state (say reader position in a file) and can produce new values when requested.

Here's an example of a reader stream that reads a file in chunks in Swift 4.2:

final class ChunkReader {