Skip to content

Instantly share code, notes, and snippets.

View MaxDesiatov's full-sized avatar

Max Desiatov MaxDesiatov

View GitHub Profile
MaxDesiatov /
Last active September 12, 2018 13:24
Pitch for generator syntax in Swift

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 {