diff --git a/Guides/BufferedBytes.md b/Guides/BufferedBytes.md index 166fc51..ce1d0ef 100644 --- a/Guides/BufferedBytes.md +++ b/Guides/BufferedBytes.md @@ -40,13 +40,13 @@ public struct AsyncBufferedByteIterator: AsyncIteratorProtocol, Sendable { } ``` -For each invocation of `next` the iterator will check if a buffer has been filled. If the buffer is filled with some amount of bytes a fast path is taken to directly return a byte out of that buffer. If the buffer is not filled then the read function is invoked to acquire the next filled buffer and then it takes a byte out of that buffer. +For each invocation of `next`, the iterator will check if a buffer has been filled. If the buffer is filled with some amount of bytes, a fast path is taken to directly return a byte out of that buffer. If the buffer is not filled, the read function is invoked to acquire the next filled buffer, at which point it takes a byte out of that buffer. -If the read function returns 0 indicating it read no more bytes the iterator is claimed to be finished and no additional invocations to the read function are made. +If the read function returns `0`, indicating it didn't read any more bytes, the iterator is decided to be finished and no additional invocations to the read function are made. -If the read function throws the error will be thrown by the iteration. Subsequent invocations to the iterator will return nil without invoking the read function. +If the read function throws, the error will be thrown by the iteration. Subsequent invocations to the iterator will then return `nil` without invoking the read function. -During the iteration if the task is cancelled the iteration will check the cancellation only in passes where the read function is invoked and will throw a `CancellationError`. +If the task is cancelled during the iteration, the iteration will check the cancellation only in passes where the read function is invoked, and will throw a `CancellationError`. ### Naming diff --git a/Guides/Chain.md b/Guides/Chain.md index a5f7003..60938b0 100644 --- a/Guides/Chain.md +++ b/Guides/Chain.md @@ -20,11 +20,11 @@ for try await line in lines { } ``` -The above example shows how two `AsyncSequence` types can be chained together. In this case it prepends a preamble to the lines content of the file. +The above example shows how two `AsyncSequence` types can be chained together. In this case it prepends a preamble to the `lines` content of the file. ## Detailed Design -This function family and the associated family of return types are prime candidates for variadic generics. Until that proposal is accepted these will be implemented in terms of two and three base sequence cases. +This function family and the associated family of return types are prime candidates for variadic generics. Until that proposal is accepted, these will be implemented in terms of two- and three-base sequence cases. ```swift public func chain(_ s1: Base1, _ s2: Base2) -> AsyncChain2Sequence where Base1.Element == Base2.Element @@ -62,12 +62,12 @@ The `chain(_:...)` function takes two or more sequences as arguments. The resulting `AsyncChainSequence` type is an asynchronous sequence, with conditional conformance to `Sendable` when the arguments conform. -When any of the asynchronous sequences being chained together come to their end of iteration the `AsyncChainSequence` iteration proceeds on to the next asynchronous sequence. When the last asynchronous sequence reaches the end of iteration the `AsyncChainSequence` then ends its iteration. At any point in time if one of the comprising asynchronous sequences ever throw an error during iteration the resulting `AsyncChainSequence` iteration will throw that error and end iteration. +When any of the asynchronous sequences being chained together come to their end of iteration, the `AsyncChainSequence` iteration proceeds to the next asynchronous sequence. When the last asynchronous sequence reaches the end of iteration, the `AsyncChainSequence` then ends its iteration. -The throwing behavior of `AsyncChainSequence` is that it will throw when any of its comprising bases throw, and will not throw when all of its comprising bases do not throw. +At any point in time, if one of the comprising asynchronous sequences throws an error during iteration, the resulting `AsyncChainSequence` iteration will throw that error and end iteration. The throwing behavior of `AsyncChainSequence` is that it will throw when any of its comprising bases throw, and will not throw when all of its comprising bases do not throw. ### Naming This function's and type's name match the term of art used in other languages and libraries. -This combinator function is a direct analog to the synchronous version [defined in the Swift Algorithms package](https://github.com/apple/swift-algorithms/blob/main/Guides/Chain.md). \ No newline at end of file +This combinator function is a direct analog to the synchronous version [defined in the Swift Algorithms package](https://github.com/apple/swift-algorithms/blob/main/Guides/Chain.md). diff --git a/Guides/CombineLatest.md b/Guides/CombineLatest.md index b20053b..1462172 100644 --- a/Guides/CombineLatest.md +++ b/Guides/CombineLatest.md @@ -25,7 +25,7 @@ Given some sample inputs the following combined events can be expected. ## Detailed Design -This function family and the associated family of return types are prime candidates for variadic generics. Until that proposal is accepted these will be implemented in terms of two and three base sequence cases. +This function family and the associated family of return types are prime candidates for variadic generics. Until that proposal is accepted, these will be implemented in terms of two- and three-base sequence cases. ```swift public func combineLatest(_ base1: Base1, _ base2: Base2) -> AsyncCombineLatest2Sequence @@ -62,13 +62,13 @@ public struct AsyncCombineLatest3Sequence(_ base1: Base1, _ base2: Base2) -> AsyncMerge2Sequence @@ -64,17 +64,17 @@ public struct AsyncMerge3Sequence(_ base1: Base1, _ base2: Base2) -> AsyncZip2Sequence @@ -64,17 +64,17 @@ public struct AsyncZip3Sequence UInt8? { diff --git a/Sources/AsyncAlgorithms/AsyncExclusiveReductionsSequence.swift b/Sources/AsyncAlgorithms/AsyncExclusiveReductionsSequence.swift index 031aff9..1244d7a 100644 --- a/Sources/AsyncAlgorithms/AsyncExclusiveReductionsSequence.swift +++ b/Sources/AsyncAlgorithms/AsyncExclusiveReductionsSequence.swift @@ -18,8 +18,8 @@ extension AsyncSequence { /// /// - Parameters: /// - initial: The value to use as the initial value. - /// - transform: A closure that combines the previously reduced result and - /// the next element in the receiving asynchronous sequence. + /// - transform: A closure that combines the previously-reduced result and + /// the next element in the receiving asynchronous sequence, which it returns. /// - Returns: An asynchronous sequence of the initial value followed by the reduced /// elements. @inlinable @@ -37,8 +37,9 @@ extension AsyncSequence { /// /// - Parameters: /// - initial: The value to use as the initial value. - /// - transform: A closure that combines the previously reduced result and - /// the next element in the receiving asynchronous sequence. + /// - transform: A closure that combines the previously-reduced result and + /// the next element in the receiving asynchronous sequence, mutating the + /// previous result instead of returning a value. /// - Returns: An asynchronous sequence of the initial value followed by the reduced /// elements. @inlinable diff --git a/Sources/AsyncAlgorithms/AsyncInclusiveReductionsSequence.swift b/Sources/AsyncAlgorithms/AsyncInclusiveReductionsSequence.swift index 5cdbc0e..7df0fc2 100644 --- a/Sources/AsyncAlgorithms/AsyncInclusiveReductionsSequence.swift +++ b/Sources/AsyncAlgorithms/AsyncInclusiveReductionsSequence.swift @@ -13,7 +13,8 @@ extension AsyncSequence { /// ``` /// /// - Parameter transform: A closure that combines the previously reduced - /// result and the next element in the receiving sequence. + /// result and the next element in the receiving sequence, and returns + /// the result. /// - Returns: An asynchronous sequence of the reduced elements. @inlinable public func reductions( diff --git a/Sources/AsyncAlgorithms/AsyncInterspersedSequence.swift b/Sources/AsyncAlgorithms/AsyncInterspersedSequence.swift index 179abd9..9ac7f97 100644 --- a/Sources/AsyncAlgorithms/AsyncInterspersedSequence.swift +++ b/Sources/AsyncAlgorithms/AsyncInterspersedSequence.swift @@ -10,21 +10,21 @@ //===----------------------------------------------------------------------===// extension AsyncSequence { - /// Returns an async sequence containing elements of this async sequence with + /// Returns an asynchronous sequence containing elements of this asynchronous sequence with /// the given separator inserted in between each element. /// - /// Any value of the async sequence's element type can be used as the separator. + /// Any value of the asynchronous sequence's element type can be used as the separator. /// - /// - Parameter separator: Value to insert in between each of this async + /// - Parameter separator: The value to insert in between each of this async /// sequence’s elements. - /// - Returns: The interspersed async sequence of elements. + /// - Returns: The interspersed asynchronous sequence of elements. @inlinable public func interspersed(with separator: Element) -> AsyncInterspersedSequence { AsyncInterspersedSequence(self, separator: separator) } } -/// An async sequence that presents the elements of a base async sequence of +/// An asynchronous sequence that presents the elements of a base asynchronous sequence of /// elements with a separator between each of those elements. public struct AsyncInterspersedSequence { @usableFromInline @@ -43,7 +43,7 @@ public struct AsyncInterspersedSequence { extension AsyncInterspersedSequence: AsyncSequence { public typealias Element = Base.Element - /// The iterator for an `AsyncInterspersedSequence` async sequence. + /// The iterator for an `AsyncInterspersedSequence` asynchronous sequence. public struct Iterator: AsyncIteratorProtocol { @usableFromInline internal enum State { diff --git a/Sources/AsyncAlgorithms/AsyncLazySequence.swift b/Sources/AsyncAlgorithms/AsyncLazySequence.swift index 44ea066..b8eed7e 100644 --- a/Sources/AsyncAlgorithms/AsyncLazySequence.swift +++ b/Sources/AsyncAlgorithms/AsyncLazySequence.swift @@ -11,7 +11,7 @@ extension Sequence { /// An asynchronous sequence containing the same elements as this sequence, - /// but on which operations, such as `map` and `filter`, are + /// but on which operations, such as `map` and `filter`, are /// implemented asynchronously. @inlinable public var async: AsyncLazySequence { @@ -26,7 +26,7 @@ extension Sequence { /// asynchronous sequences. /// /// This functions similarly to `LazySequence` by accessing elemetns sequentially -/// in the iterators next method. +/// in the iterator's `next()` method. @frozen public struct AsyncLazySequence: AsyncSequence { public typealias Element = Base.Element diff --git a/Sources/AsyncAlgorithms/AsyncThrowingExclusiveReductionsSequence.swift b/Sources/AsyncAlgorithms/AsyncThrowingExclusiveReductionsSequence.swift index 66ea480..8915f56 100644 --- a/Sources/AsyncAlgorithms/AsyncThrowingExclusiveReductionsSequence.swift +++ b/Sources/AsyncAlgorithms/AsyncThrowingExclusiveReductionsSequence.swift @@ -11,7 +11,7 @@ extension AsyncSequence { /// Returns an asynchronous sequence containing the accumulated results of combining the - /// elements of the asynchronous sequence using the given closure. + /// elements of the asynchronous sequence using the given error-throwing closure. /// /// This can be seen as applying the reduce function to each element and /// providing the initial value followed by these results as an asynchronous sequence. @@ -19,7 +19,8 @@ extension AsyncSequence { /// - Parameters: /// - initial: The value to use as the initial value. /// - transform: A closure that combines the previously reduced result and - /// the next element in the receiving asynchronous sequence. + /// the next element in the receiving asynchronous sequence and returns + /// the result. If the closure throws an error, the sequence throws. /// - Returns: An asynchronous sequence of the initial value followed by the reduced /// elements. @inlinable @@ -30,7 +31,7 @@ extension AsyncSequence { } /// Returns an asynchronous sequence containing the accumulated results of combining the - /// elements of the asynchronous sequence using the given closure. + /// elements of the asynchronous sequence using the given error-throwing closure. /// /// This can be seen as applying the reduce function to each element and /// providing the initial value followed by these results as an asynchronous sequence. @@ -38,7 +39,9 @@ extension AsyncSequence { /// - Parameters: /// - initial: The value to use as the initial value. /// - transform: A closure that combines the previously reduced result and - /// the next element in the receiving asynchronous sequence. + /// the next element in the receiving asynchronous sequence, mutating the + /// previous result instead of returning a value. If the closure throws an + /// error, the sequence throws. /// - Returns: An asynchronous sequence of the initial value followed by the reduced /// elements. @inlinable @@ -47,8 +50,8 @@ extension AsyncSequence { } } -/// An asynchronous sequence of applying a transform to the element of an asynchronous sequence and the -/// previously transformed result. +/// An asynchronous sequence of applying an error-throwing transform to the element of +/// an asynchronous sequence and the previously transformed result. @frozen public struct AsyncThrowingExclusiveReductionsSequence { @usableFromInline diff --git a/Sources/AsyncAlgorithms/AsyncThrowingInclusiveReductionsSequence.swift b/Sources/AsyncAlgorithms/AsyncThrowingInclusiveReductionsSequence.swift index f41d874..f1abdb5 100644 --- a/Sources/AsyncAlgorithms/AsyncThrowingInclusiveReductionsSequence.swift +++ b/Sources/AsyncAlgorithms/AsyncThrowingInclusiveReductionsSequence.swift @@ -1,6 +1,6 @@ extension AsyncSequence { /// Returns an asynchronous sequence containing the accumulated results of combining the - /// elements of the asynchronous sequence using the given closure. + /// elements of the asynchronous sequence using the given error-throwing closure. /// /// This can be seen as applying the reduce function to each element and /// providing the initial value followed by these results as an asynchronous sequence. @@ -13,7 +13,8 @@ extension AsyncSequence { /// ``` /// /// - Parameter transform: A closure that combines the previously reduced - /// result and the next element in the receiving sequence. + /// result and the next element in the receiving sequence. If the closure + /// throws an error, the sequence throws. /// - Returns: An asynchronous sequence of the reduced elements. @inlinable public func reductions( diff --git a/Sources/AsyncAlgorithms/Dictionary.swift b/Sources/AsyncAlgorithms/Dictionary.swift index 86ccf0f..78437b1 100644 --- a/Sources/AsyncAlgorithms/Dictionary.swift +++ b/Sources/AsyncAlgorithms/Dictionary.swift @@ -44,7 +44,8 @@ extension Dictionary { /// dictionary. /// - combine: A closure that is called with the values for any duplicate /// keys that are encountered. The closure returns the desired value for - /// the final dictionary. + /// the final dictionary, or throws an error if building the dictionary + /// can't proceed. @inlinable public init(_ keysAndValues: S, uniquingKeysWith combine: (Value, Value) async throws -> Value) async rethrows where S.Element == (Key, Value) { self.init() diff --git a/Sources/AsyncAlgorithms/RangeReplaceableCollection.swift b/Sources/AsyncAlgorithms/RangeReplaceableCollection.swift index 6615e09..fedcf3b 100644 --- a/Sources/AsyncAlgorithms/RangeReplaceableCollection.swift +++ b/Sources/AsyncAlgorithms/RangeReplaceableCollection.swift @@ -12,7 +12,7 @@ extension RangeReplaceableCollection { /// Creates a new instance of a collection containing the elements of an asynchronous sequence. /// - /// - Parameter surce: The asynchronous sequence of elements for the new collection. + /// - Parameter source: The asynchronous sequence of elements for the new collection. @inlinable public init(_ source: Source) async rethrows where Source.Element == Element { self.init()