Skip to content

Commit 718d647

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

13 files changed

+50
-0
lines changed

Sources/AsyncAlgorithms/AsyncCompactedSequence.swift

+1
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

+1
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

+3
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

+3
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

+3
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

+7
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

+6
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

+7
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

+1
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

+3
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

Sources/AsyncAlgorithms/AsyncTimerSequence.swift

+5
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12+
/// An `AsyncSequence` that produces elements at regular intervals.
1213
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
1314
public struct AsyncTimerSequence<C: Clock>: AsyncSequence {
1415
public typealias Element = C.Instant
1516

17+
/// The iterator for an `AsyncTimerSequence` instance.
1618
public struct Iterator: AsyncIteratorProtocol {
1719
var clock: C?
1820
let interval: C.Instant.Duration
@@ -57,6 +59,7 @@ public struct AsyncTimerSequence<C: Clock>: AsyncSequence {
5759
let interval: C.Instant.Duration
5860
let tolerance: C.Instant.Duration?
5961

62+
/// Create an `AsyncTimerSequence` with a given repeating interval.
6063
public init(interval: C.Instant.Duration, tolerance: C.Instant.Duration? = nil, clock: C) {
6164
self.clock = clock
6265
self.interval = interval
@@ -70,13 +73,15 @@ public struct AsyncTimerSequence<C: Clock>: AsyncSequence {
7073

7174
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
7275
extension AsyncTimerSequence {
76+
/// Create an `AsyncTimerSequence` with a given repeating interval.
7377
public static func repeating(every interval: C.Instant.Duration, tolerance: C.Instant.Duration? = nil, clock: C) -> AsyncTimerSequence<C> {
7478
return AsyncTimerSequence(interval: interval, tolerance: tolerance, clock: clock)
7579
}
7680
}
7781

7882
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
7983
extension AsyncTimerSequence where C == SuspendingClock {
84+
/// Create an `AsyncTimerSequence` with a given repeating interval.
8085
public static func repeating(every interval: Duration, tolerance: Duration? = nil) -> AsyncTimerSequence<SuspendingClock> {
8186
return AsyncTimerSequence(interval: interval, tolerance: tolerance, clock: SuspendingClock())
8287
}

Sources/AsyncAlgorithms/AsyncZip2Sequence.swift

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12+
/// Creates an asynchronous sequence that concurrently awaits values from two `AsyncSequence` types
13+
/// by emitting a tuple of the values.
1214
public func zip<Base1: AsyncSequence, Base2: AsyncSequence>(_ base1: Base1, _ base2: Base2) -> AsyncZip2Sequence<Base1, Base2>
1315
where Base1: Sendable,
1416
Base2: Sendable,
@@ -19,6 +21,8 @@ public func zip<Base1: AsyncSequence, Base2: AsyncSequence>(_ base1: Base1, _ ba
1921
AsyncZip2Sequence(base1, base2)
2022
}
2123

24+
/// An asynchronous sequence that concurrently awaits values from two `AsyncSequence` types
25+
/// by emitting a tuple of the values.
2226
public struct AsyncZip2Sequence<Base1: AsyncSequence, Base2: AsyncSequence>: Sendable
2327
where Base1: Sendable,
2428
Base2: Sendable,
@@ -38,6 +42,7 @@ public struct AsyncZip2Sequence<Base1: AsyncSequence, Base2: AsyncSequence>: Sen
3842
extension AsyncZip2Sequence: AsyncSequence {
3943
public typealias Element = (Base1.Element, Base2.Element)
4044

45+
/// The iterator for an `AsyncZip2Sequence` instance.
4146
public struct Iterator: AsyncIteratorProtocol, Sendable {
4247
var base1: Base1.AsyncIterator?
4348
var base2: Base2.AsyncIterator?

Sources/AsyncAlgorithms/AsyncZip3Sequence.swift

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12+
/// Creates an asynchronous sequence that concurrently awaits values from three `AsyncSequence` types
13+
/// by emitting a tuple of the values.
1214
public func zip<Base1: AsyncSequence, Base2: AsyncSequence, Base3: AsyncSequence>(_ base1: Base1, _ base2: Base2, _ base3: Base3) -> AsyncZip3Sequence<Base1, Base2, Base3>
1315
where Base1: Sendable,
1416
Base2: Sendable,
@@ -22,6 +24,8 @@ public func zip<Base1: AsyncSequence, Base2: AsyncSequence, Base3: AsyncSequence
2224
AsyncZip3Sequence(base1, base2, base3)
2325
}
2426

27+
/// An asynchronous sequence that concurrently awaits values from three `AsyncSequence` types
28+
/// by emitting a tuple of the values.
2529
public struct AsyncZip3Sequence<Base1: AsyncSequence, Base2: AsyncSequence, Base3: AsyncSequence>: Sendable
2630
where Base1: Sendable,
2731
Base2: Sendable,
@@ -46,6 +50,7 @@ public struct AsyncZip3Sequence<Base1: AsyncSequence, Base2: AsyncSequence, Base
4650
extension AsyncZip3Sequence: AsyncSequence {
4751
public typealias Element = (Base1.Element, Base2.Element, Base3.Element)
4852

53+
/// The iterator for an `AsyncZip3Sequence` instance.
4954
public struct Iterator: AsyncIteratorProtocol, Sendable {
5055
var base1: Base1.AsyncIterator?
5156
var base2: Base2.AsyncIterator?

0 commit comments

Comments
 (0)