Skip to content

[stdlib] Gardening BackDeployConcurrency files #62504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ extension AsyncSequence {
/// returns `nil` in this case, which `compactMap(_:)` omits from the
/// transformed asynchronous sequence.
///
/// let romanNumeralDict: [Int : String] =
/// let romanNumeralDict: [Int: String] =
/// [1: "I", 2: "II", 3: "III", 5: "V"]
///
/// let stream = Counter(howHigh: 5)
/// .compactMap { romanNumeralDict[$0] }
/// for await numeral in stream {
/// print("\(numeral) ", terminator: " ")
/// print(numeral, terminator: " ")
/// }
/// // Prints: I II III V
/// // Prints "I II III V "
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you think this doesn't need to be rear-spaced, just let me know.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think including the quotes is an improvement. It makes it easier to see that the output from print includes a space at the end.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good! I'll change stdlib/public/Concurrency files too and submit a new PR on the weekend. Thanks!

///
/// - Parameter transform: A mapping closure. `transform` accepts an element
/// of this sequence as its parameter and returns a transformed value of the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ extension AsyncSequence {
///
/// In this example, an asynchronous sequence called `Counter` produces `Int`
/// values from `1` to `10`. The `dropFirst(_:)` method causes the modified
/// sequence to ignore the values `0` through `4`, and instead emit `5` through `10`:
/// sequence to ignore the values `1` through `3`, and instead emit `4` through `10`:
Copy link
Contributor Author

@Jager-yoo Jager-yoo Dec 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note here: These numbers need to be fixed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the old numbers were wrong. The list starts at 1, not a 0.

///
/// for await number in Counter(howHigh: 10).dropFirst(3) {
/// print("\(number) ", terminator: " ")
/// print(number, terminator: " ")
/// }
/// // prints "4 5 6 7 8 9 10"
/// // Prints "4 5 6 7 8 9 10 "
///
/// If the number of elements to drop exceeds the number of elements in the
/// sequence, the result is an empty sequence.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ extension AsyncSequence {
/// let stream = Counter(howHigh: 10)
/// .drop { $0 % 3 != 0 }
/// for await number in stream {
/// print("\(number) ", terminator: " ")
/// print(number, terminator: " ")
/// }
/// // prints "3 4 5 6 7 8 9 10"
/// // Prints "3 4 5 6 7 8 9 10 "
///
/// After the predicate returns `false`, the sequence never executes it again,
/// and from then on the sequence passes through elements from its underlying
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ extension AsyncSequence {
/// let stream = Counter(howHigh: 10)
/// .filter { $0 % 2 == 0 }
/// for await number in stream {
/// print("\(number) ", terminator: " ")
/// print(number, terminator: " ")
/// }
/// // Prints: 2 4 6 8 10
/// // Prints "2 4 6 8 10 "
///
/// - Parameter isIncluded: A closure that takes an element of the
/// asynchronous sequence as its argument and returns a Boolean value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ extension AsyncSequence {
/// let stream = Counter(howHigh: 5)
/// .flatMap { Counter(howHigh: $0) }
/// for await number in stream {
/// print("\(number)", terminator: " ")
/// print(number, terminator: " ")
/// }
/// // Prints: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5
/// // Prints "1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 "
///
/// - Parameter transform: A mapping closure. `transform` accepts an element
/// of this sequence as its parameter and returns an `AsyncSequence`.
/// - Returns: A single, flattened asynchronous sequence that contains all
/// elements in all the asychronous sequences produced by `transform`.
/// elements in all the asynchronous sequences produced by `transform`.
@inlinable
public __consuming func flatMap<SegmentOfResult: AsyncSequence>(
_ transform: @escaping (Element) async -> SegmentOfResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,19 @@ import Swift
/// conforms to `AsyncIteratorProtocol`. The following example shows a `Counter`
/// type that uses an inner iterator to monotonically generate `Int` values
/// until reaching a `howHigh` value. While this example isn't itself
/// asychronous, it shows the shape of a custom sequence and iterator, and how
/// asynchronous, it shows the shape of a custom sequence and iterator, and how
/// to use it as if it were asynchronous:
///
/// struct Counter : AsyncSequence {
/// struct Counter: AsyncSequence {
/// typealias Element = Int
/// let howHigh: Int
///
/// struct AsyncIterator : AsyncIteratorProtocol {
/// struct AsyncIterator: AsyncIteratorProtocol {
/// let howHigh: Int
/// var current = 1
///
/// mutating func next() async -> Int? {
/// // A genuinely asychronous implementation uses the `Task`
/// // A genuinely asynchronous implementation uses the `Task`
/// // API to check for cancellation here and return early.
/// guard current <= howHigh else {
/// return nil
Expand All @@ -56,10 +57,10 @@ import Swift
///
/// At the call site, this looks like:
///
/// for await i in Counter(howHigh: 10) {
/// print(i, terminator: " ")
/// for await number in Counter(howHigh: 10) {
/// print(number, terminator: " ")
Comment on lines +60 to +61
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed i to number just like the other examples.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks like a good change to me. It's consistent, and "number" means more to the reader than "i".

/// }
/// // Prints: 1 2 3 4 5 6 7 8 9 10
/// // Prints "1 2 3 4 5 6 7 8 9 10 "
///
/// ### End of Iteration
///
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/BackDeployConcurrency/AsyncMapSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ extension AsyncSequence {
/// let stream = Counter(howHigh: 5)
/// .map { romanNumeralDict[$0] ?? "(unknown)" }
/// for await numeral in stream {
/// print("\(numeral) ", terminator: " ")
/// print(numeral, terminator: " ")
/// }
/// // Prints: I II III (unknown) V
/// // Prints "I II III (unknown) V "
///
/// - Parameter transform: A mapping closure. `transform` accepts an element
/// of this sequence as its parameter and returns a transformed value of the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ extension AsyncSequence {
/// sequence to pass through the first six values, then end.
///
/// for await number in Counter(howHigh: 10).prefix(6) {
/// print("\(number) ")
/// print(number, terminator: " ")
/// }
/// // prints "1 2 3 4 5 6"
/// // Prints "1 2 3 4 5 6 "
///
/// If the count passed to `prefix(_:)` exceeds the number of elements in the
/// base sequence, the result contains all of the elements in the sequence.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ extension AsyncSequence {
/// let stream = Counter(howHigh: 10)
/// .prefix { $0 % 2 != 0 || $0 % 3 != 0 }
/// for try await number in stream {
/// print("\(number) ", terminator: " ")
/// print(number, terminator: " ")
/// }
/// // prints "1 2 3 4 5"
/// // Prints "1 2 3 4 5 "
///
/// - Parameter predicate: A closure that takes an element as a parameter and
/// returns a Boolean value indicating whether the element should be
Expand Down
26 changes: 13 additions & 13 deletions stdlib/public/BackDeployConcurrency/AsyncSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import Swift
/// over `Counter`, a custom `AsyncSequence` that produces `Int` values from
/// `1` up to a `howHigh` value:
///
/// for await i in Counter(howHigh: 10) {
/// print(i, terminator: " ")
/// for await number in Counter(howHigh: 10) {
/// print(number, terminator: " ")
/// }
/// // Prints: 1 2 3 4 5 6 7 8 9 10
/// // Prints "1 2 3 4 5 6 7 8 9 10 "
///
/// An `AsyncSequence` doesn't generate or contain the values; it just defines
/// how you access them. Along with defining the type of values as an associated
Expand Down Expand Up @@ -69,7 +69,7 @@ import Swift
/// for await s in stream {
/// print(s, terminator: " ")
/// }
/// // Prints: Odd Even Odd Even Odd Even Odd Even Odd Even
/// // Prints "Odd Even Odd Even Odd Even Odd Even Odd Even "
///
@available(SwiftStdlib 5.1, *)
@rethrows
Expand Down Expand Up @@ -108,7 +108,7 @@ extension AsyncSequence {
/// $0 + $1
/// }
/// print(sum)
/// // Prints: 10
/// // Prints "10"
///
///
/// - Parameters:
Expand Down Expand Up @@ -204,7 +204,7 @@ extension AsyncSequence {
/// let containsDivisibleByThree = await Counter(howHigh: 10)
/// .contains { $0 % 3 == 0 }
/// print(containsDivisibleByThree)
/// // Prints: true
/// // Prints "true"
///
/// The predicate executes each time the asynchronous sequence produces an
/// element, until either the predicate finds a match or the sequence ends.
Expand All @@ -231,7 +231,7 @@ extension AsyncSequence {
/// let allLessThanTen = await Counter(howHigh: 10)
/// .allSatisfy { $0 < 10 }
/// print(allLessThanTen)
/// // Prints: false
/// // Prints "false"
///
/// The predicate executes each time the asynchronous sequence produces an
/// element, until either the predicate returns `false` or the sequence ends.
Expand Down Expand Up @@ -263,7 +263,7 @@ extension AsyncSequence where Element: Equatable {
/// let containsFive = await Counter(howHigh: 10)
/// .contains(5)
/// print(containsFive)
/// // Prints: true
/// // Prints "true"
///
/// - Parameter search: The element to find in the asynchronous sequence.
/// - Returns: `true` if the method found the element in the asynchronous
Expand Down Expand Up @@ -306,7 +306,7 @@ extension AsyncSequence {
/// let divisibleBy2And3 = await Counter(howHigh: 10)
/// .first { $0 % 2 == 0 && $0 % 3 == 0 }
/// print(divisibleBy2And3 ?? "none")
/// // Prints: 6
/// // Prints "6"
///
/// The predicate executes each time the asynchronous sequence produces an
/// element, until either the predicate finds a match or the sequence ends.
Expand Down Expand Up @@ -357,7 +357,7 @@ extension AsyncSequence {
/// let min = await RankCounter()
/// .min { $0.rawValue < $1.rawValue }
/// print(min ?? "none")
/// // Prints: ace
/// // Prints "ace"
///
/// - Parameter areInIncreasingOrder: A predicate that returns `true` if its
/// first argument should be ordered before its second argument; otherwise,
Expand Down Expand Up @@ -412,7 +412,7 @@ extension AsyncSequence {
/// let max = await RankCounter()
/// .max { $0.rawValue < $1.rawValue }
/// print(max ?? "none")
/// // Prints: king
/// // Prints "king"
///
/// - Parameter areInIncreasingOrder: A predicate that returns `true` if its
/// first argument should be ordered before its second argument; otherwise,
Expand Down Expand Up @@ -449,7 +449,7 @@ extension AsyncSequence where Element: Comparable {
/// let min = await Counter(howHigh: 10)
/// .min()
/// print(min ?? "none")
/// // Prints: 1
/// // Prints "1"
///
/// - Returns: The sequence’s minimum element. If the sequence has no
/// elements, returns `nil`.
Expand All @@ -469,7 +469,7 @@ extension AsyncSequence where Element: Comparable {
/// let max = await Counter(howHigh: 10)
/// .max()
/// print(max ?? "none")
/// // Prints: 10
/// // Prints "10"
///
/// - Returns: The sequence’s maximum element. If the sequence has no
/// elements, returns `nil`.
Expand Down
32 changes: 15 additions & 17 deletions stdlib/public/BackDeployConcurrency/AsyncStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ import Swift
/// produces it:
///
/// for await quake in QuakeMonitor.quakes {
/// print ("Quake: \(quake.date)")
/// print("Quake: \(quake.date)")
/// }
/// print ("Stream finished.")
/// print("Stream finished.")
///
@available(SwiftStdlib 5.1, *)
public struct AsyncStream<Element> {
Expand Down Expand Up @@ -177,7 +177,7 @@ public struct AsyncStream<Element> {
let storage: _Storage

/// Resume the task awaiting the next iteration point by having it return
/// nomally from its suspension point with a given element.
/// normally from its suspension point with a given element.
///
/// - Parameter value: The value to yield from the continuation.
/// - Returns: A `YieldResult` that indicates the success or failure of the
Expand Down Expand Up @@ -270,18 +270,18 @@ public struct AsyncStream<Element> {
///
/// let stream = AsyncStream<Int>(Int.self,
/// bufferingPolicy: .bufferingNewest(5)) { continuation in
/// Task.detached {
/// for _ in 0..<100 {
/// await Task.sleep(1 * 1_000_000_000)
/// continuation.yield(Int.random(in: 1...10))
/// }
/// continuation.finish()
/// Task.detached {
/// for _ in 0..<100 {
/// await Task.sleep(1 * 1_000_000_000)
/// continuation.yield(Int.random(in: 1...10))
/// }
/// continuation.finish()
/// }
/// }
///
/// // Call point:
/// for await random in stream {
/// print ("\(random)")
/// print(random)
/// }
///
public init(
Expand All @@ -303,7 +303,7 @@ public struct AsyncStream<Element> {
/// stream.
/// - onCancel: A closure to execute when canceling the stream's task.
///
/// Use this convenience initializer when you have an asychronous function
/// Use this convenience initializer when you have an asynchronous function
/// that can produce elements for the stream, and don't want to invoke
/// a continuation manually. This initializer "unfolds" your closure into
/// an asynchronous stream. The created stream handles conformance
Expand All @@ -317,15 +317,13 @@ public struct AsyncStream<Element> {
/// the `unfolding` parameter label.
///
/// let stream = AsyncStream<Int> {
/// await Task.sleep(1 * 1_000_000_000)
/// return Int.random(in: 1...10)
/// }
/// onCancel: { @Sendable () in print ("Canceled.") }
/// )
/// await Task.sleep(1 * 1_000_000_000)
/// return Int.random(in: 1...10)
/// } onCancel: { @Sendable () in print("Canceled.") }
///
/// // Call point:
/// for await random in stream {
/// print ("\(random)")
/// print(random)
/// }
///
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extension AsyncSequence {
/// transformed asynchronous sequence. When the value is `5`, the closure
/// throws `MyError`, terminating the sequence.
///
/// let romanNumeralDict: [Int : String] =
/// let romanNumeralDict: [Int: String] =
/// [1: "I", 2: "II", 3: "III", 5: "V"]
///
/// do {
Expand All @@ -42,12 +42,12 @@ extension AsyncSequence {
/// return romanNumeralDict[value]
/// }
/// for try await numeral in stream {
/// print("\(numeral) ", terminator: " ")
/// print(numeral, terminator: " ")
/// }
/// } catch {
/// print("Error: \(error)")
/// }
/// // Prints: I II III Error: MyError()
/// // Prints "I II III Error: MyError() "
///
/// - Parameter transform: An error-throwing mapping closure. `transform`
/// accepts an element of this sequence as its parameter and returns a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ extension AsyncSequence {
/// throws without ever printing anything.
///
/// do {
/// let stream = Counter(howHigh: 10)
/// let stream = Counter(howHigh: 10)
/// .drop {
/// if $0 % 2 == 0 {
/// throw EvenError()
/// }
/// return $0 < 5
/// }
/// for try await number in stream {
/// print("\(number) ")
/// print(number)
/// }
/// } catch {
/// print ("\(error)")
/// print(error)
/// }
/// // Prints: EvenError()
/// // Prints "EvenError()"
///
/// After the predicate returns `false`, the sequence never executes it again,
/// and from then on the sequence passes through elements from its underlying
Expand Down
Loading