diff --git a/Sources/AsyncAlgorithms/AsyncAdjacentPairsSequence.swift b/Sources/AsyncAlgorithms/AsyncAdjacentPairsSequence.swift index 2a37f918..b1a0a156 100644 --- a/Sources/AsyncAlgorithms/AsyncAdjacentPairsSequence.swift +++ b/Sources/AsyncAlgorithms/AsyncAdjacentPairsSequence.swift @@ -9,6 +9,29 @@ // //===----------------------------------------------------------------------===// +extension AsyncSequence { + /// An `AsyncSequence` that iterates over the adjacent pairs of the original + /// original `AsyncSequence`. + /// + /// ``` + /// for await (first, second) in (1...5).async.adjacentPairs() { + /// print("First: \(first), Second: \(second)") + /// } + /// + /// // First: 1, Second: 2 + /// // First: 2, Second: 3 + /// // First: 3, Second: 4 + /// // First: 4, Second: 5 + /// ``` + /// + /// - Returns: An `AsyncSequence` where the element is a tuple of two adjacent elements + /// or the original `AsyncSequence`. + @inlinable + public func adjacentPairs() -> AsyncAdjacentPairsSequence { + AsyncAdjacentPairsSequence(self) + } +} + /// An `AsyncSequence` that iterates over the adjacent pairs of the original /// `AsyncSequence`. @frozen @@ -60,29 +83,6 @@ public struct AsyncAdjacentPairsSequence: AsyncSequence { } } -extension AsyncSequence { - /// An `AsyncSequence` that iterates over the adjacent pairs of the original - /// original `AsyncSequence`. - /// - /// ``` - /// for await (first, second) in (1...5).async.adjacentPairs() { - /// print("First: \(first), Second: \(second)") - /// } - /// - /// // First: 1, Second: 2 - /// // First: 2, Second: 3 - /// // First: 3, Second: 4 - /// // First: 4, Second: 5 - /// ``` - /// - /// - Returns: An `AsyncSequence` where the element is a tuple of two adjacent elements - /// or the original `AsyncSequence`. - @inlinable - public func adjacentPairs() -> AsyncAdjacentPairsSequence { - AsyncAdjacentPairsSequence(self) - } -} - extension AsyncAdjacentPairsSequence: Sendable where Base: Sendable, Base.Element: Sendable { } @available(*, unavailable) diff --git a/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Timer.md b/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Timer.md index 8228a4e2..1419d68b 100644 --- a/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Timer.md +++ b/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Timer.md @@ -42,7 +42,7 @@ extension AsyncTimerSequence: Sendable { } extension AsyncTimerSequence.Iterator: Sendable { } ``` -Since all the types comprising `AsyncTimerSequence` and it's `Iterator` are `Sendable` these types are also `Sendable`. +Since all the types comprising `AsyncTimerSequence` are `Sendable` these types are also `Sendable`. ## Credits/Inspiration diff --git a/Sources/AsyncAlgorithms/AsyncChain3Sequence.swift b/Sources/AsyncAlgorithms/AsyncChain3Sequence.swift index 1c275a2c..e88e3584 100644 --- a/Sources/AsyncAlgorithms/AsyncChain3Sequence.swift +++ b/Sources/AsyncAlgorithms/AsyncChain3Sequence.swift @@ -95,3 +95,6 @@ extension AsyncChain3Sequence: AsyncSequence { } extension AsyncChain3Sequence: Sendable where Base1: Sendable, Base2: Sendable, Base3: Sendable { } + +@available(*, unavailable) +extension AsyncChain3Sequence.Iterator: Sendable { } diff --git a/Sources/AsyncAlgorithms/AsyncChunkedByGroupSequence.swift b/Sources/AsyncAlgorithms/AsyncChunkedByGroupSequence.swift index 26faafe5..0ce5d199 100644 --- a/Sources/AsyncAlgorithms/AsyncChunkedByGroupSequence.swift +++ b/Sources/AsyncAlgorithms/AsyncChunkedByGroupSequence.swift @@ -117,4 +117,6 @@ public struct AsyncChunkedByGroupSequence() -> AsyncCompactedSequence + where Element == Unwrapped? { + AsyncCompactedSequence(self) + } +} + /// An `AsyncSequence` that iterates over every non-nil element from the original /// `AsyncSequence`. @frozen @@ -50,22 +66,7 @@ public struct AsyncCompactedSequence: AsyncSequenc } } -extension AsyncSequence { - /// Returns a new `AsyncSequence` that iterates over every non-nil element from the - /// original `AsyncSequence`. - /// - /// Produces the same result as `c.compactMap { $0 }`. - /// - /// - Returns: An `AsyncSequence` where the element is the unwrapped original - /// element and iterates over every non-nil element from the original - /// `AsyncSequence`. - /// - /// Complexity: O(1) - @inlinable - public func compacted() -> AsyncCompactedSequence - where Element == Unwrapped? { - AsyncCompactedSequence(self) - } -} - extension AsyncCompactedSequence: Sendable where Base: Sendable, Base.Element: Sendable { } + +@available(*, unavailable) +extension AsyncCompactedSequence.Iterator: Sendable { } diff --git a/Sources/AsyncAlgorithms/AsyncExclusiveReductionsSequence.swift b/Sources/AsyncAlgorithms/AsyncExclusiveReductionsSequence.swift index 0d56c593..cef05359 100644 --- a/Sources/AsyncAlgorithms/AsyncExclusiveReductionsSequence.swift +++ b/Sources/AsyncAlgorithms/AsyncExclusiveReductionsSequence.swift @@ -112,3 +112,6 @@ extension AsyncExclusiveReductionsSequence: AsyncSequence { } extension AsyncExclusiveReductionsSequence: Sendable where Base: Sendable, Element: Sendable { } + +@available(*, unavailable) +extension AsyncExclusiveReductionsSequence.Iterator: Sendable { } diff --git a/Sources/AsyncAlgorithms/AsyncInclusiveReductionsSequence.swift b/Sources/AsyncAlgorithms/AsyncInclusiveReductionsSequence.swift index 0dab7cb0..ca907b80 100644 --- a/Sources/AsyncAlgorithms/AsyncInclusiveReductionsSequence.swift +++ b/Sources/AsyncAlgorithms/AsyncInclusiveReductionsSequence.swift @@ -85,3 +85,6 @@ extension AsyncInclusiveReductionsSequence: AsyncSequence { } extension AsyncInclusiveReductionsSequence: Sendable where Base: Sendable { } + +@available(*, unavailable) +extension AsyncInclusiveReductionsSequence.Iterator: Sendable { } diff --git a/Sources/AsyncAlgorithms/AsyncJoinedBySeparatorSequence.swift b/Sources/AsyncAlgorithms/AsyncJoinedBySeparatorSequence.swift index e401eea2..515d8a8e 100644 --- a/Sources/AsyncAlgorithms/AsyncJoinedBySeparatorSequence.swift +++ b/Sources/AsyncAlgorithms/AsyncJoinedBySeparatorSequence.swift @@ -142,3 +142,6 @@ public struct AsyncJoinedBySeparatorSequence: AsyncSequence where Base extension AsyncJoinedSequence: Sendable where Base: Sendable, Base.Element: Sendable, Base.Element.Element: Sendable { } + +@available(*, unavailable) +extension AsyncJoinedSequence.Iterator: Sendable { } diff --git a/Sources/AsyncAlgorithms/AsyncRemoveDuplicatesSequence.swift b/Sources/AsyncAlgorithms/AsyncRemoveDuplicatesSequence.swift index fd1d2192..0f45e21d 100644 --- a/Sources/AsyncAlgorithms/AsyncRemoveDuplicatesSequence.swift +++ b/Sources/AsyncAlgorithms/AsyncRemoveDuplicatesSequence.swift @@ -143,3 +143,9 @@ public struct AsyncThrowingRemoveDuplicatesSequence: AsyncS extension AsyncRemoveDuplicatesSequence: Sendable where Base: Sendable, Base.Element: Sendable { } extension AsyncThrowingRemoveDuplicatesSequence: Sendable where Base: Sendable, Base.Element: Sendable { } + +@available(*, unavailable) +extension AsyncRemoveDuplicatesSequence.Iterator: Sendable { } + +@available(*, unavailable) +extension AsyncThrowingRemoveDuplicatesSequence.Iterator: Sendable { } diff --git a/Sources/AsyncAlgorithms/AsyncSyncSequence.swift b/Sources/AsyncAlgorithms/AsyncSyncSequence.swift index 6710df7c..70a6637b 100644 --- a/Sources/AsyncAlgorithms/AsyncSyncSequence.swift +++ b/Sources/AsyncAlgorithms/AsyncSyncSequence.swift @@ -67,3 +67,6 @@ public struct AsyncSyncSequence: AsyncSequence { } extension AsyncSyncSequence: Sendable where Base: Sendable { } + +@available(*, unavailable) +extension AsyncSyncSequence.Iterator: Sendable { } diff --git a/Sources/AsyncAlgorithms/AsyncThrottleSequence.swift b/Sources/AsyncAlgorithms/AsyncThrottleSequence.swift index 4832b9ac..ae2b1db4 100644 --- a/Sources/AsyncAlgorithms/AsyncThrottleSequence.swift +++ b/Sources/AsyncAlgorithms/AsyncThrottleSequence.swift @@ -102,3 +102,6 @@ extension AsyncThrottleSequence: AsyncSequence { @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) extension AsyncThrottleSequence: Sendable where Base: Sendable, Element: Sendable { } + +@available(*, unavailable) +extension AsyncThrottleSequence.Iterator: Sendable { } diff --git a/Sources/AsyncAlgorithms/AsyncThrowingExclusiveReductionsSequence.swift b/Sources/AsyncAlgorithms/AsyncThrowingExclusiveReductionsSequence.swift index 4b12c2c3..1cb49d8b 100644 --- a/Sources/AsyncAlgorithms/AsyncThrowingExclusiveReductionsSequence.swift +++ b/Sources/AsyncAlgorithms/AsyncThrowingExclusiveReductionsSequence.swift @@ -119,3 +119,6 @@ extension AsyncThrowingExclusiveReductionsSequence: AsyncSequence { } extension AsyncThrowingExclusiveReductionsSequence: Sendable where Base: Sendable, Element: Sendable { } + +@available(*, unavailable) +extension AsyncThrowingExclusiveReductionsSequence.Iterator: Sendable { } diff --git a/Sources/AsyncAlgorithms/AsyncThrowingInclusiveReductionsSequence.swift b/Sources/AsyncAlgorithms/AsyncThrowingInclusiveReductionsSequence.swift index 2a03304f..7779a842 100644 --- a/Sources/AsyncAlgorithms/AsyncThrowingInclusiveReductionsSequence.swift +++ b/Sources/AsyncAlgorithms/AsyncThrowingInclusiveReductionsSequence.swift @@ -1,3 +1,14 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Async Algorithms open source project +// +// Copyright (c) 2022 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// +//===----------------------------------------------------------------------===// + extension AsyncSequence { /// Returns an asynchronous sequence containing the accumulated results of combining the /// elements of the asynchronous sequence using the given error-throwing closure. @@ -89,3 +100,6 @@ extension AsyncThrowingInclusiveReductionsSequence: AsyncSequence { } extension AsyncThrowingInclusiveReductionsSequence: Sendable where Base: Sendable { } + +@available(*, unavailable) +extension AsyncThrowingInclusiveReductionsSequence.Iterator: Sendable { } diff --git a/Sources/AsyncAlgorithms/AsyncTimerSequence.swift b/Sources/AsyncAlgorithms/AsyncTimerSequence.swift index fe3b58f6..f3a06fc0 100644 --- a/Sources/AsyncAlgorithms/AsyncTimerSequence.swift +++ b/Sources/AsyncAlgorithms/AsyncTimerSequence.swift @@ -89,3 +89,6 @@ extension AsyncTimerSequence where C == SuspendingClock { @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) extension AsyncTimerSequence: Sendable { } + +@available(*, unavailable) +extension AsyncTimerSequence.Iterator: Sendable { } diff --git a/Sources/AsyncAlgorithms/Channels/AsyncChannel.swift b/Sources/AsyncAlgorithms/Channels/AsyncChannel.swift index 8035d06a..f59b6b5f 100644 --- a/Sources/AsyncAlgorithms/Channels/AsyncChannel.swift +++ b/Sources/AsyncAlgorithms/Channels/AsyncChannel.swift @@ -58,3 +58,6 @@ public final class AsyncChannel: AsyncSequence, @unchecked Se } } } + +@available(*, unavailable) +extension AsyncChannel.Iterator: Sendable { } diff --git a/Sources/AsyncAlgorithms/Channels/AsyncThrowingChannel.swift b/Sources/AsyncAlgorithms/Channels/AsyncThrowingChannel.swift index 2fc48dfe..eaa55fcc 100644 --- a/Sources/AsyncAlgorithms/Channels/AsyncThrowingChannel.swift +++ b/Sources/AsyncAlgorithms/Channels/AsyncThrowingChannel.swift @@ -61,3 +61,6 @@ public final class AsyncThrowingChannel: Asyn } } } + +@available(*, unavailable) +extension AsyncThrowingChannel.Iterator: Sendable { } diff --git a/Sources/AsyncAlgorithms/CombineLatest/AsyncCombineLatest2Sequence.swift b/Sources/AsyncAlgorithms/CombineLatest/AsyncCombineLatest2Sequence.swift index f8fd86cc..fa68acf7 100644 --- a/Sources/AsyncAlgorithms/CombineLatest/AsyncCombineLatest2Sequence.swift +++ b/Sources/AsyncAlgorithms/CombineLatest/AsyncCombineLatest2Sequence.swift @@ -87,3 +87,6 @@ public struct AsyncCombineLatest2Sequence< } } } + +@available(*, unavailable) +extension AsyncCombineLatest2Sequence.Iterator: Sendable { } diff --git a/Sources/AsyncAlgorithms/CombineLatest/AsyncCombineLatest3Sequence.swift b/Sources/AsyncAlgorithms/CombineLatest/AsyncCombineLatest3Sequence.swift index a1c7e51a..4353c0b0 100644 --- a/Sources/AsyncAlgorithms/CombineLatest/AsyncCombineLatest3Sequence.swift +++ b/Sources/AsyncAlgorithms/CombineLatest/AsyncCombineLatest3Sequence.swift @@ -97,3 +97,6 @@ public struct AsyncCombineLatest3Sequence< } } } + +@available(*, unavailable) +extension AsyncCombineLatest3Sequence.Iterator: Sendable { } diff --git a/Sources/AsyncAlgorithms/Debounce/AsyncDebounceSequence.swift b/Sources/AsyncAlgorithms/Debounce/AsyncDebounceSequence.swift index e2f8b7a9..888d4f42 100644 --- a/Sources/AsyncAlgorithms/Debounce/AsyncDebounceSequence.swift +++ b/Sources/AsyncAlgorithms/Debounce/AsyncDebounceSequence.swift @@ -53,20 +53,20 @@ public struct AsyncDebounceSequence: Sendable whe extension AsyncDebounceSequence: AsyncSequence { public typealias Element = Base.Element - public func makeAsyncIterator() -> AsyncIterator { + public func makeAsyncIterator() -> Iterator { let storage = DebounceStorage( base: self.base, interval: self.interval, tolerance: self.tolerance, clock: self.clock ) - return AsyncIterator(storage: storage) + return Iterator(storage: storage) } } @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) extension AsyncDebounceSequence { - public struct AsyncIterator: AsyncIteratorProtocol { + public struct Iterator: AsyncIteratorProtocol { /// This class is needed to hook the deinit to observe once all references to the ``AsyncIterator`` are dropped. /// /// If we get move-only types we should be able to drop this class and use the `deinit` of the ``AsyncIterator`` struct itself. @@ -97,3 +97,6 @@ extension AsyncDebounceSequence { } } } + +@available(*, unavailable) +extension AsyncDebounceSequence.Iterator: Sendable { } diff --git a/Sources/AsyncAlgorithms/Merge/AsyncMerge2Sequence.swift b/Sources/AsyncAlgorithms/Merge/AsyncMerge2Sequence.swift index c1a45ba3..2de482c8 100644 --- a/Sources/AsyncAlgorithms/Merge/AsyncMerge2Sequence.swift +++ b/Sources/AsyncAlgorithms/Merge/AsyncMerge2Sequence.swift @@ -50,18 +50,18 @@ public struct AsyncMerge2Sequence< } extension AsyncMerge2Sequence: AsyncSequence { - public func makeAsyncIterator() -> AsyncIterator { + public func makeAsyncIterator() -> Iterator { let storage = MergeStorage( base1: base1, base2: base2, base3: nil ) - return AsyncIterator(storage: storage) + return Iterator(storage: storage) } } extension AsyncMerge2Sequence { - public struct AsyncIterator: AsyncIteratorProtocol { + public struct Iterator: AsyncIteratorProtocol { /// This class is needed to hook the deinit to observe once all references to the ``AsyncIterator`` are dropped. /// /// If we get move-only types we should be able to drop this class and use the `deinit` of the ``AsyncIterator`` struct itself. @@ -92,3 +92,6 @@ extension AsyncMerge2Sequence { } } } + +@available(*, unavailable) +extension AsyncMerge2Sequence.Iterator: Sendable { } diff --git a/Sources/AsyncAlgorithms/Merge/AsyncMerge3Sequence.swift b/Sources/AsyncAlgorithms/Merge/AsyncMerge3Sequence.swift index 6f5abf13..8cafcd95 100644 --- a/Sources/AsyncAlgorithms/Merge/AsyncMerge3Sequence.swift +++ b/Sources/AsyncAlgorithms/Merge/AsyncMerge3Sequence.swift @@ -61,18 +61,18 @@ public struct AsyncMerge3Sequence< } extension AsyncMerge3Sequence: AsyncSequence { - public func makeAsyncIterator() -> AsyncIterator { + public func makeAsyncIterator() -> Iterator { let storage = MergeStorage( base1: base1, base2: base2, base3: base3 ) - return AsyncIterator(storage: storage) + return Iterator(storage: storage) } } public extension AsyncMerge3Sequence { - struct AsyncIterator: AsyncIteratorProtocol { + struct Iterator: AsyncIteratorProtocol { /// This class is needed to hook the deinit to observe once all references to the ``AsyncIterator`` are dropped. /// /// If we get move-only types we should be able to drop this class and use the `deinit` of the ``AsyncIterator`` struct itself. @@ -103,3 +103,6 @@ public extension AsyncMerge3Sequence { } } } + +@available(*, unavailable) +extension AsyncMerge3Sequence.Iterator: Sendable { } diff --git a/Sources/AsyncAlgorithms/PartialIteration.swift b/Sources/AsyncAlgorithms/PartialIteration.swift deleted file mode 100644 index 1404ddc2..00000000 --- a/Sources/AsyncAlgorithms/PartialIteration.swift +++ /dev/null @@ -1,47 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Async Algorithms open source project -// -// Copyright (c) 2022 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -//===----------------------------------------------------------------------===// - -enum PartialIteration: CustomStringConvertible { - case idle(Iterator) - case pending(Task) - case terminal - - var description: String { - switch self { - case .idle: return "idle" - case .pending: return "pending" - case .terminal: return "terminal" - } - } - - mutating func resolve(_ result: Result, _ iterator: Iterator) rethrows -> Iterator.Element? { - do { - guard let value = try result._rethrowGet() else { - self = .terminal - return nil - } - self = .idle(iterator) - return value - } catch { - self = .terminal - throw error - } - } - - mutating func cancel() { - if case .pending(let task) = self { - task.cancel() - } - self = .terminal - } -} - -extension PartialIteration: Sendable where Iterator: Sendable, Iterator.Element: Sendable { } diff --git a/Sources/AsyncAlgorithms/Zip/AsyncZip2Sequence.swift b/Sources/AsyncAlgorithms/Zip/AsyncZip2Sequence.swift index 6fb341ac..34e42913 100644 --- a/Sources/AsyncAlgorithms/Zip/AsyncZip2Sequence.swift +++ b/Sources/AsyncAlgorithms/Zip/AsyncZip2Sequence.swift @@ -69,3 +69,6 @@ public struct AsyncZip2Sequence: Asy } } } + +@available(*, unavailable) +extension AsyncZip2Sequence.Iterator: Sendable { } diff --git a/Sources/AsyncAlgorithms/Zip/AsyncZip3Sequence.swift b/Sources/AsyncAlgorithms/Zip/AsyncZip3Sequence.swift index 87474bae..513dc27a 100644 --- a/Sources/AsyncAlgorithms/Zip/AsyncZip3Sequence.swift +++ b/Sources/AsyncAlgorithms/Zip/AsyncZip3Sequence.swift @@ -74,3 +74,6 @@ public struct AsyncZip3Sequence