Skip to content

Commit 61c79f3

Browse files
committed
[stdlib] Address feedback from @airspeedswift and @CodaFi
1 parent a63f5bf commit 61c79f3

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

stdlib/public/core/CollectionOfOne.swift

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ extension IteratorOverOne: IteratorProtocol, Sequence {
4545

4646
/// A collection containing a single element.
4747
///
48-
/// You can use a `CollectionOfOne` instance to efficiently represent a
49-
/// collection with only one element. For example, you can add a single element
50-
/// to an array by using a `CollectionOfOne` instance with the concatenation
51-
/// operator (`+`):
48+
/// You can use a `CollectionOfOne` instance when you need to efficiently
49+
/// represent a single value as a collection. For example, you can add a
50+
/// single element to an array by using a `CollectionOfOne` instance with the
51+
/// concatenation operator (`+`):
5252
///
5353
/// let a = [1, 2, 3, 4]
5454
/// let toAdd = 100
@@ -59,7 +59,9 @@ public struct CollectionOfOne<Element> {
5959
@usableFromInline // FIXME(sil-serialize-all)
6060
internal var _element: Element
6161

62-
/// Creates an instance containing just `element`.
62+
/// Creates an instance containing just the given element.
63+
///
64+
/// - Parameter element: The element to store in the collection.
6365
@inlinable // FIXME(sil-serialize-all)
6466
public init(_ element: Element) {
6567
self._element = element
@@ -90,8 +92,7 @@ extension CollectionOfOne: RandomAccessCollection, MutableCollection {
9092

9193
/// Returns the position immediately after the given index.
9294
///
93-
/// - Parameter i: A valid index of the collection. `i` must be less than
94-
/// `endIndex`.
95+
/// - Parameter i: A valid index of the collection. `i` must be `0`.
9596
/// - Returns: The index value immediately after `i`.
9697
@inlinable // FIXME(sil-serialize-all)
9798
public func index(after i: Int) -> Int {
@@ -101,8 +102,7 @@ extension CollectionOfOne: RandomAccessCollection, MutableCollection {
101102

102103
/// Returns the position immediately before the given index.
103104
///
104-
/// - Parameter i: A valid index of the collection. `i` must be greater than
105-
/// `startIndex`.
105+
/// - Parameter i: A valid index of the collection. `i` must be `1`.
106106
/// - Returns: The index value immediately before `i`.
107107
@inlinable // FIXME(sil-serialize-all)
108108
public func index(before i: Int) -> Int {
@@ -118,9 +118,10 @@ extension CollectionOfOne: RandomAccessCollection, MutableCollection {
118118
return IteratorOverOne(_elements: _element)
119119
}
120120

121-
/// Accesses the element at `position`.
121+
/// Accesses the element at the specified position.
122122
///
123-
/// The only valid position in a `CollectionOfOne` instance is `0`.
123+
/// - Parameter position: The position of the element to access. The only
124+
/// valid position in a `CollectionOfOne` instance is `0`.
124125
@inlinable // FIXME(sil-serialize-all)
125126
public subscript(position: Int) -> Element {
126127
get {

stdlib/public/core/CompilerProtocols.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,17 +197,21 @@ public func != <T : Equatable>(lhs: T, rhs: T) -> Bool
197197
/// // Prints "There are 4 directions."
198198
/// let caseList = CompassDirection.allCases
199199
/// .map({ "\($0)" })
200-
/// .joined(separator: ", "))
200+
/// .joined(separator: ", ")
201201
/// // caseList == "north, south, east, west"
202202
///
203203
/// Conforming to the CaseIterable Protocol
204204
/// =======================================
205205
///
206206
/// The compiler can automatically provide an implementation of the
207-
/// `CaseIterable` requirements for any enumeration without associated values.
208-
/// To take advantage of this automatic synthesis when defining your own custom
209-
/// enumeration, specify conformance to the `CaseIterable` protocol in the
210-
/// original declaration.
207+
/// `CaseIterable` requirements for any enumeration without associated values
208+
/// or `@available` attributes on its cases. The synthesized `allCases`
209+
/// collection provides the cases in order of their declaration.
210+
///
211+
/// You can take advantage of this compiler support when defining your own
212+
/// custom enumeration by declaring conformance to `CaseIterable` in the
213+
/// enumeration's original declaration. The `CompassDirection` example above
214+
/// demonstrates this automatic implementation.
211215
public protocol CaseIterable {
212216
/// A type that can represent a collection of all values of this type.
213217
associatedtype AllCases: Collection

0 commit comments

Comments
 (0)