Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ var veryLargeSequence = try await iterator.collect(1024*1024*1024) { sequence ->
}
```

In the above example, our sequence transform gives us access to a sequence that will be at most `1024*1024*1024` bytes large, which is 1 GB! However, instead of accumulating that data into an array, we get a sequence back, which we can attach an iterator map to so we can process the data 1 MB at a time, combining that data into a `DataFrame` type. When, we can consume this transformed sequence, reducing it to calculate averages for each data frame, and storing those averages in a `Summary` object.
In the above example, our sequence transform gives us access to a sequence that will be at most `1024*1024*1024` bytes large, which is 1 GB! However, instead of accumulating that data into an array, we get a sequence back, which we can attach an iterator map to so we can process the data 1 MB at a time, combining that data into a `DataFrame` type. Then, we can consume this transformed sequence, reducing it to calculate averages for each data frame, and storing those averages in a `Summary` object.

Note that this whole time, no more than around 1 MB of memory will be used at a time, because it'll only actually be consumes while reducing the results, which will only read 1 MB of data at a time, and will stop once a total of 1 GB of data has been read.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extension AsyncIteratorProtocol {
/// Asynchronously advances by the specified number of elements, or ends the sequence if there is no next element.
///
/// If a complete array could not be collected, an error is thrown and the sequence should be considered finished.
/// - Parameter count: The number of bytes to collect.
/// - Parameter count: The number of elements to collect.
/// - Returns: A collection with exactly `count` elements, or `nil` if the sequence is finished.
/// - Throws: `AsyncSequenceReaderError.insufficientElements` if a complete byte sequence could not be returned by the time the sequence ended.
public mutating func collect(_ count: Int) async throws -> [Element]? {
Expand Down