Skip to content

Commit a82d266

Browse files
committed
Reformat comments.
Only use doc comments for doc. Wrap all to 80 columns. Also removed high-level explanation of split operation, so it isn't taken to be an explanation of this particular split algorithm.
1 parent d30e7ae commit a82d266

File tree

2 files changed

+61
-78
lines changed

2 files changed

+61
-78
lines changed

Sources/Algorithms/LazySplitCollection.swift

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,23 @@ public struct LazySplitCollection<Base: Collection> {
4242
splitCount: Int.max
4343
)
4444

45-
/// We precalculate `startIndex`. There are three possibilities:
46-
/// 1. `base` is empty and we're _not_ omitting empty subsequences, in which
47-
/// case the following index describes the sole element of this collection;
45+
// We precalculate `startIndex`. There are three possibilities:
46+
// 1. `base` is empty and we're _not_ omitting empty subsequences, in which
47+
// case the following index describes the sole element of this collection;
4848
self._startIndex = Index(
4949
baseRange: base.startIndex..<base.startIndex,
5050
sequenceLength: 1,
5151
splitCount: 0
5252
)
5353
if base.isEmpty {
5454
if omittingEmptySubsequences {
55-
/// 2. `base` is empty and we _are_ omitting empty subsequences, so this
56-
/// collection has no elements;
55+
// 2. `base` is empty and we _are_ omitting empty subsequences, so this
56+
// collection has no elements;
5757
_startIndex = _endIndex
5858
}
5959
} else {
60-
/// 3. `base` isn't empty, so we must iterate it to determine the start index.
60+
// 3. `base` isn't empty, so we must iterate it to determine the start
61+
// index.
6162
_startIndex = indexForSubsequence(
6263
atOrAfter: base.startIndex,
6364
sequenceLength: 0,
@@ -75,6 +76,8 @@ extension LazySplitCollection: LazyCollectionProtocol {
7576
/// The number of subsequences up to and including this position in the
7677
/// collection.
7778
internal let sequenceLength: Int
79+
/// The number splits performed up to and including this position in the
80+
/// collection.
7881
internal let splitCount: Int
7982

8083
internal init(
@@ -98,7 +101,8 @@ extension LazySplitCollection: LazyCollectionProtocol {
98101
}
99102
}
100103

101-
/// Returns the index of the subsequence starting at or after the given base collection index.
104+
/// Returns the index of the subsequence starting at or after the given base
105+
/// collection index.
102106
internal func indexForSubsequence(
103107
atOrAfter lowerBound: Base.Index,
104108
sequenceLength: Int,
@@ -169,10 +173,10 @@ extension LazySplitCollection: LazyCollectionProtocol {
169173
if !omittingEmptySubsequences
170174
&& i.sequenceLength < i.splitCount + 1
171175
{
172-
/// The base collection ended with a separator, so we need to emit one
173-
/// more empty subsequence. This one differs from `endIndex` in its
174-
/// `sequenceLength` (except in an extreme edge case!), which is the
175-
/// sole property tested for equality and comparison.
176+
// The base collection ended with a separator, so we need to emit one
177+
// more empty subsequence. This one differs from `endIndex` in its
178+
// `sequenceLength` (except in an extreme edge case!), which is the
179+
// sole property tested for equality and comparison.
176180
return Index(
177181
baseRange: base.endIndex..<base.endIndex,
178182
sequenceLength: i.sequenceLength + 1,
@@ -199,18 +203,19 @@ extension LazySplitCollection: LazyCollectionProtocol {
199203
extension LazySplitCollection.Index: Hashable where Base.Index: Hashable {}
200204

201205
extension LazyCollectionProtocol {
202-
/// Lazily returns the longest possible subsequences of the collection, in order,
203-
/// that don't contain elements satisfying the given predicate.
206+
/// Lazily returns the longest possible subsequences of the collection, in
207+
/// order, that don't contain elements satisfying the given predicate.
204208
///
205-
/// The resulting lazy collection consists of at most `maxSplits + 1` subsequences.
206-
/// Elements that are used to split the collection are not returned as part of any
207-
/// subsequence (except possibly the last one, in the case where `maxSplits` is
208-
/// less than the number of separators in the collection).
209+
/// The resulting lazy collection consists of at most `maxSplits + 1`
210+
/// subsequences. Elements that are used to split the collection are not
211+
/// returned as part of any subsequence (except possibly the last one, in the
212+
/// case where `maxSplits` is less than the number of separators in the
213+
/// collection).
209214
///
210215
/// The following examples show the effects of the `maxSplits` and
211-
/// `omittingEmptySubsequences` parameters when lazily splitting a string using a
212-
/// closure that matches spaces. The first use of `split` returns each word
213-
/// that was originally separated by one or more spaces.
216+
/// `omittingEmptySubsequences` parameters when lazily splitting a string
217+
/// using a closure that matches spaces. The first use of `split` returns each
218+
/// word that was originally separated by one or more spaces.
214219
///
215220
/// let line = "BLANCHE: I don't want realism. I want magic!"
216221
/// for spaceless in line.lazy.split(whereSeparator: { $0 == " " }) {
@@ -298,13 +303,14 @@ extension LazyCollectionProtocol {
298303

299304
extension LazyCollectionProtocol
300305
where Element: Equatable {
301-
/// Lazily returns the longest possible subsequences of the collection, in order,
302-
/// around elements equal to the given element.
306+
/// Lazily returns the longest possible subsequences of the collection, in
307+
/// order, around elements equal to the given element.
303308
///
304-
/// The resulting lazy collection consists of at most `maxSplits + 1` subsequences.
305-
/// Elements that are used to split the collection are not returned as part of any
306-
/// subsequence (except possibly the last one, in the case where `maxSplits` is
307-
/// less than the number of separators in the collection).
309+
/// The resulting lazy collection consists of at most `maxSplits + 1`
310+
/// subsequences. Elements that are used to split the collection are not
311+
/// returned as part of any subsequence (except possibly the last one, in the
312+
/// case where `maxSplits` is less than the number of separators in the
313+
/// collection).
308314
///
309315
/// The following examples show the effects of the `maxSplits` and
310316
/// `omittingEmptySubsequences` parameters when splitting a string at each

Sources/Algorithms/LazySplitSequence.swift

Lines changed: 29 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -52,40 +52,6 @@ extension LazySplitSequence {
5252

5353
extension LazySplitSequence.Iterator: IteratorProtocol {
5454
public mutating func next() -> Element? {
55-
/// Separators mark the points where we want to split (cut in two) the base
56-
/// collection, removing the separator in the process.
57-
///
58-
/// Each split yields two subsequences, though splitting at the start or end
59-
/// of a sequence yields an empty subsequence where there were no elements
60-
/// adjacent to the cut.
61-
///
62-
/// Thus the maximum number of subsequences returned after iterating the
63-
/// entire base collection (including empty ones, if they are not omitted)
64-
/// will be at most one more than the number of splits made (equivalently,
65-
/// one more than the number of separators encountered).
66-
///
67-
/// The number of splits is limited by `maxSplits`, and thus may be less
68-
/// than the total number of separators in the base collection.
69-
///
70-
/// [1, 2, 42, 3, 4, 42, 5].split(separator: 42,
71-
/// omittingEmptySubsequences: false)
72-
/// // first split -> [1, 2], [3, 4, 42, 5]
73-
/// // last split -> [1, 2], [3, 4], [5]
74-
///
75-
/// [1, 2, 42, 3, 4, 42, 5, 42].split(separator: 42,
76-
/// maxSplits: 2,
77-
/// omittingEmptySubsequences: false)
78-
/// // first split -> [1, 2], [3, 4, 42, 5, 42]
79-
/// // last split -> [1, 2], [3, 4], [5, 42]
80-
///
81-
/// [42, 1, 42].split(separator: 42, omittingEmptySubsequences: false)
82-
/// // first split -> [], [1, 42]
83-
/// // last split -> [], [1], []
84-
///
85-
/// [42, 42].split(separator: 42, omittingEmptySubsequences: false)
86-
/// // first split -> [], [42]
87-
/// // last split -> [], [], []
88-
8955
var currentElement = base.next()
9056
var subsequence: Element = []
9157

@@ -136,18 +102,19 @@ extension LazySplitSequence: LazySequenceProtocol {
136102
}
137103

138104
extension LazySequenceProtocol {
139-
/// Lazily returns the longest possible subsequences of the sequence, in order,
140-
/// that don't contain elements satisfying the given predicate.
105+
/// Lazily returns the longest possible subsequences of the sequence, in
106+
/// order, that don't contain elements satisfying the given predicate.
141107
///
142-
/// The resulting lazy sequence consists of at most `maxSplits + 1` subsequences.
143-
/// Elements that are used to split the sequence are not returned as part of any
144-
/// subsequence (except possibly the last one, in the case where `maxSplits` is
145-
/// less than the number of separators in the sequence).
108+
/// The resulting lazy sequence consists of at most `maxSplits + 1`
109+
/// subsequences. Elements that are used to split the sequence are not
110+
/// returned as part of any subsequence (except possibly the last one, in the
111+
/// case where `maxSplits` is less than the number of separators in the
112+
/// sequence).
146113
///
147114
/// The following examples show the effects of the `maxSplits` and
148-
/// `omittingEmptySubsequences` parameters when lazily splitting a string using a
149-
/// closure that matches spaces. The first use of `split` returns each word
150-
/// that was originally separated by one or more spaces.
115+
/// `omittingEmptySubsequences` parameters when lazily splitting a string
116+
/// using a closure that matches spaces. The first use of `split` returns each
117+
/// word that was originally separated by one or more spaces.
151118
///
152119
/// let line = "BLANCHE: I don't want realism. I want magic!"
153120
/// for spaceless in line.lazy.split(whereSeparator: { $0 == " " }) {
@@ -166,7 +133,10 @@ extension LazySequenceProtocol {
166133
/// The second example passes `1` for the `maxSplits` parameter, so the
167134
/// original string is split just once, into two new strings.
168135
///
169-
/// for spaceless in line.lazy.split(maxSplits: 1, whereSeparator: { $0 == " " }) {
136+
/// for spaceless in line.lazy.split(
137+
/// maxSplits: 1,
138+
/// whereSeparator: { $0 == " " }
139+
/// ) {
170140
/// print(spaceless)
171141
/// }
172142
/// // Prints
@@ -177,7 +147,10 @@ extension LazySequenceProtocol {
177147
/// parameter, so the returned array contains empty strings where spaces
178148
/// were repeated.
179149
///
180-
/// for spaceless in line.lazy.split(omittingEmptySubsequences: false, whereSeparator: { $0 == " " }) {
150+
/// for spaceless in line.lazy.split(
151+
/// omittingEmptySubsequences: false,
152+
/// whereSeparator: { $0 == " " }
153+
/// ) {
181154
/// print(spaceless)
182155
/// }
183156
/// // Prints
@@ -228,13 +201,14 @@ extension LazySequenceProtocol {
228201
}
229202

230203
extension LazySequenceProtocol where Element: Equatable {
231-
/// Lazily returns the longest possible subsequences of the sequence, in order,
232-
/// around elements equal to the given element.
204+
/// Lazily returns the longest possible subsequences of the sequence, in
205+
/// order, around elements equal to the given element.
233206
///
234-
/// The resulting lazy sequence consists of at most `maxSplits + 1` subsequences.
235-
/// Elements that are used to split the sequence are not returned as part of any
236-
/// subsequence (except possibly the last one, in the case where `maxSplits` is
237-
/// less than the number of separators in the sequence).
207+
/// The resulting lazy sequence consists of at most `maxSplits + 1`
208+
/// subsequences. Elements that are used to split the sequence are not
209+
/// returned as part of any subsequence (except possibly the last one, in the
210+
/// case where `maxSplits` is less than the number of separators in the
211+
/// sequence).
238212
///
239213
/// The following examples show the effects of the `maxSplits` and
240214
/// `omittingEmptySubsequences` parameters when splitting a string at each
@@ -269,7 +243,10 @@ extension LazySequenceProtocol where Element: Equatable {
269243
/// parameter, so the returned array contains empty strings where spaces
270244
/// were repeated.
271245
///
272-
/// for spaceless in line.lazy.split(separator: " ", omittingEmptySubsequences: false) {
246+
/// for spaceless in line.lazy.split(
247+
/// separator: " ",
248+
/// omittingEmptySubsequences: false
249+
/// ) {
273250
/// print(spaceless)
274251
/// }
275252
/// // Prints

0 commit comments

Comments
 (0)