Skip to content

Commit 718d647

Browse files
authored
Add a smattering of brief inline docs for most functions/types (#97)
1 parent d4bdb34 commit 718d647

13 files changed

+50
-0
lines changed

Sources/AsyncAlgorithms/AsyncCompactedSequence.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public struct AsyncCompactedSequence<Base: AsyncSequence, Element>: AsyncSequenc
2323
self.base = base
2424
}
2525

26+
/// The iterator for an `AsyncCompactedSequence` instance.
2627
@frozen
2728
public struct Iterator: AsyncIteratorProtocol {
2829
@usableFromInline

Sources/AsyncAlgorithms/AsyncExclusiveReductionsSequence.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public struct AsyncExclusiveReductionsSequence<Base: AsyncSequence, Element> {
7070
}
7171

7272
extension AsyncExclusiveReductionsSequence: AsyncSequence {
73+
/// The iterator for an `AsyncExclusiveReductionsSequence` instance.
7374
@frozen
7475
public struct Iterator: AsyncIteratorProtocol {
7576
@usableFromInline

Sources/AsyncAlgorithms/AsyncInclusiveReductionsSequence.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ extension AsyncSequence {
2525
}
2626
}
2727

28+
/// An asynchronous sequence containing the accumulated results of combining the
29+
/// elements of the asynchronous sequence using a given closure.
2830
@frozen
2931
public struct AsyncInclusiveReductionsSequence<Base: AsyncSequence> {
3032
@usableFromInline
@@ -43,6 +45,7 @@ public struct AsyncInclusiveReductionsSequence<Base: AsyncSequence> {
4345
extension AsyncInclusiveReductionsSequence: AsyncSequence {
4446
public typealias Element = Base.Element
4547

48+
/// The iterator for an `AsyncInclusiveReductionsSequence` instance.
4649
@frozen
4750
public struct Iterator: AsyncIteratorProtocol {
4851
@usableFromInline

Sources/AsyncAlgorithms/AsyncJoinedBySeparatorSequence.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
extension AsyncSequence where Element: AsyncSequence {
13+
/// Concatenate an `AsyncSequence` of `AsyncSequence` elements with a seperator.
1314
@inlinable
1415
public func joined<Separator: AsyncSequence>(separator: Separator) -> AsyncJoinedBySeparatorSequence<Self, Separator> {
1516
return AsyncJoinedBySeparatorSequence(self, separator: separator)
1617
}
1718
}
1819

20+
/// An `AsyncSequence` that concatenates`AsyncSequence` elements with a seperator.
1921
public struct AsyncJoinedBySeparatorSequence<Base: AsyncSequence, Separator: AsyncSequence>: AsyncSequence where Base.Element: AsyncSequence, Separator.Element == Base.Element.Element {
2022
public typealias Element = Base.Element.Element
2123
public typealias AsyncIterator = Iterator
2224

25+
/// The iterator for an `AsyncJoinedBySeparatorSequence` instance.
2326
public struct Iterator: AsyncIteratorProtocol {
2427
@usableFromInline
2528
enum State {

Sources/AsyncAlgorithms/AsyncJoinedSequence.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
extension AsyncSequence where Element: AsyncSequence {
13+
/// Concatenate an `AsyncSequence` of `AsyncSequence` elements
1314
@inlinable
1415
public func joined() -> AsyncJoinedSequence<Self> {
1516
return AsyncJoinedSequence(self)
1617
}
1718
}
1819

20+
/// An `AsyncSequence` that concatenates`AsyncSequence` elements
1921
@frozen
2022
public struct AsyncJoinedSequence<Base: AsyncSequence>: AsyncSequence where Base.Element: AsyncSequence {
2123
public typealias Element = Base.Element.Element
2224
public typealias AsyncIterator = Iterator
2325

26+
/// The iterator for an `AsyncJoinedSequence` instance.
2427
@frozen
2528
public struct Iterator: AsyncIteratorProtocol {
2629
@usableFromInline

Sources/AsyncAlgorithms/AsyncRemoveDuplicatesSequence.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
extension AsyncSequence where Element: Equatable {
13+
/// Creates an asynchronous sequence that omits repeated elements.
1314
public func removeDuplicates() -> AsyncRemoveDuplicatesSequence<Self> {
1415
AsyncRemoveDuplicatesSequence(self) { lhs, rhs in
1516
lhs == rhs
@@ -18,18 +19,22 @@ extension AsyncSequence where Element: Equatable {
1819
}
1920

2021
extension AsyncSequence {
22+
/// Creates an asynchronous sequence that omits repeated elements by testing them with a predicate.
2123
public func removeDuplicates(by predicate: @escaping @Sendable (Element, Element) async -> Bool) -> AsyncRemoveDuplicatesSequence<Self> {
2224
return AsyncRemoveDuplicatesSequence(self, predicate: predicate)
2325
}
2426

27+
/// Creates an asynchronous sequence that omits repeated elements by testing them with a predicate.
2528
public func removeDuplicates(by predicate: @escaping @Sendable (Element, Element) async throws -> Bool) -> AsyncThrowingRemoveDuplicatesSequence<Self> {
2629
return AsyncThrowingRemoveDuplicatesSequence(self, predicate: predicate)
2730
}
2831
}
2932

33+
/// An asynchronous sequence that omits repeated elements by testing them with a predicate.
3034
public struct AsyncRemoveDuplicatesSequence<Base: AsyncSequence>: AsyncSequence {
3135
public typealias Element = Base.Element
3236

37+
/// The iterator for an `AsyncRemoveDuplicatesSequence` instance.
3338
public struct Iterator: AsyncIteratorProtocol {
3439

3540
@usableFromInline
@@ -84,9 +89,11 @@ extension AsyncRemoveDuplicatesSequence: Sendable where Base: Sendable, Base.Ele
8489
extension AsyncRemoveDuplicatesSequence.Iterator: Sendable where Base: Sendable, Base.Element: Sendable, Base.AsyncIterator: Sendable { }
8590

8691

92+
/// An asynchronous sequence that omits repeated elements by testing them with a predicate.
8793
public struct AsyncThrowingRemoveDuplicatesSequence<Base: AsyncSequence>: AsyncSequence {
8894
public typealias Element = Base.Element
8995

96+
/// The iterator for an `AsyncThrowingRemoveDuplicatesSequence` instance.
9097
public struct Iterator: AsyncIteratorProtocol {
9198

9299
@usableFromInline

Sources/AsyncAlgorithms/AsyncThrottleSequence.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
extension AsyncSequence {
13+
/// Create a rate limited `AsyncSequence` by emitting values at most every specified interval.
1314
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
1415
public func throttle<C: Clock, Reduced>(for interval: C.Instant.Duration, clock: C, reducing: @Sendable @escaping (Reduced?, Element) async -> Reduced) -> AsyncThrottleSequence<Self, C, Reduced> {
1516
AsyncThrottleSequence(self, interval: interval, clock: clock, reducing: reducing)
1617
}
1718

19+
/// Create a rate limited `AsyncSequence` by emitting values at most every specified interval.
1820
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
1921
public func throttle<Reduced>(for interval: Duration, reducing: @Sendable @escaping (Reduced?, Element) async -> Reduced) -> AsyncThrottleSequence<Self, ContinuousClock, Reduced> {
2022
throttle(for: interval, clock: .continuous, reducing: reducing)
2123
}
2224

25+
/// Create a rate limited `AsyncSequence` by emitting values at most every specified interval.
2326
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
2427
public func throttle<C: Clock>(for interval: C.Instant.Duration, clock: C, latest: Bool = true) -> AsyncThrottleSequence<Self, C, Element> {
2528
throttle(for: interval, clock: clock) { previous, element in
@@ -31,12 +34,14 @@ extension AsyncSequence {
3134
}
3235
}
3336

37+
/// Create a rate limited `AsyncSequence` by emitting values at most every specified interval.
3438
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
3539
public func throttle(for interval: Duration, latest: Bool = true) -> AsyncThrottleSequence<Self, ContinuousClock, Element> {
3640
throttle(for: interval, clock: .continuous, latest: latest)
3741
}
3842
}
3943

44+
/// A rate limited `AsyncSequence` by emitting values at most every specified interval.
4045
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
4146
public struct AsyncThrottleSequence<Base: AsyncSequence, C: Clock, Reduced> {
4247
let base: Base
@@ -56,6 +61,7 @@ public struct AsyncThrottleSequence<Base: AsyncSequence, C: Clock, Reduced> {
5661
extension AsyncThrottleSequence: AsyncSequence {
5762
public typealias Element = Reduced
5863

64+
/// The iterator for an `AsyncThrottleSequence` instance.
5965
public struct Iterator: AsyncIteratorProtocol {
6066
var base: Base.AsyncIterator
6167
let interval: C.Instant.Duration

Sources/AsyncAlgorithms/AsyncThrowingChannel.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
///
1414
/// The `AsyncThrowingChannel` class is intended to be used as a communication types between tasks., particularly when one task produces values and another task consumes those values. The back pressure applied by `send(_:)`, `fail(_:)` and `finish()` via the suspension/resume ensure that the production of values does not exceed the consumption of values from iteration. Each of these methods suspends after enqueuing the event and is resumed when the next call to `next()` on the `Iterator` is made.
1515
public final class AsyncThrowingChannel<Element: Sendable, Failure: Error>: AsyncSequence, Sendable {
16+
/// The iterator for an `AsyncThrowingChannel` instance.
1617
public struct Iterator: AsyncIteratorProtocol, Sendable {
1718
let channel: AsyncThrowingChannel<Element, Failure>
1819
var active: Bool = true
@@ -188,14 +189,20 @@ public final class AsyncThrowingChannel<Element: Sendable, Failure: Error>: Asyn
188189
continuation?.resume(with: result)
189190
}
190191

192+
/// Send an element to an awaiting iteration. This function will resume when the next call to `next()` is made.
193+
/// If the channel is already finished then this returns immediately
191194
public func send(_ element: Element) async {
192195
await _send(.success(element))
193196
}
194197

198+
/// Send an error to an awaiting iteration. This function will resume when the next call to `next()` is made.
199+
/// If the channel is already finished then this returns immediately
195200
public func fail(_ error: Error) async where Failure == Error {
196201
await _send(.failure(error))
197202
}
198203

204+
/// Send a finish to an awaiting iteration. This function will resume when the next call to `next()` is made.
205+
/// If the channel is already finished then this returns immediately
199206
public func finish() async {
200207
await _send(.success(nil))
201208
}

Sources/AsyncAlgorithms/AsyncThrowingExclusiveReductionsSequence.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public struct AsyncThrowingExclusiveReductionsSequence<Base: AsyncSequence, Elem
7272
}
7373

7474
extension AsyncThrowingExclusiveReductionsSequence: AsyncSequence {
75+
/// The iterator for an `AsyncThrowingExclusiveReductionsSequence` instance.
7576
@frozen
7677
public struct Iterator: AsyncIteratorProtocol {
7778
@usableFromInline

Sources/AsyncAlgorithms/AsyncThrowingInclusiveReductionsSequence.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ extension AsyncSequence {
2424
}
2525
}
2626

27+
/// An asynchronous sequence containing the accumulated results of combining the
28+
/// elements of the asynchronous sequence using a given error-throwing closure.
2729
@frozen
2830
public struct AsyncThrowingInclusiveReductionsSequence<Base: AsyncSequence> {
2931
@usableFromInline
@@ -42,6 +44,7 @@ public struct AsyncThrowingInclusiveReductionsSequence<Base: AsyncSequence> {
4244
extension AsyncThrowingInclusiveReductionsSequence: AsyncSequence {
4345
public typealias Element = Base.Element
4446

47+
/// The iterator for an `AsyncThrowingInclusiveReductionsSequence` instance.
4548
@frozen
4649
public struct Iterator: AsyncIteratorProtocol {
4750
@usableFromInline

0 commit comments

Comments
 (0)