Skip to content

Commit bfcaaa8

Browse files
authored
Correct Chunked documentation (#182)
* Clarify that the determining factor for being grouped is equality (`Equatable`), which doesn’t necessarily mean the _same_ value (identity) * Correct algorithmic complexity documentation on the lazy Chunked functions * Document `belongInSameGroup` and `projection`
1 parent 0f81ef4 commit bfcaaa8

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

Guides/Chunked.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ collection is bidirectional. `ChunksOfCountCollection` and
112112

113113
### Complexity
114114

115-
The eager methods are O(_n_), the lazy methods are O(_1_).
115+
The eager methods are O(_n_) where _n_ is the number of elements in the
116+
collection. The lazy methods are O(_n_) because the start index is pre-computed.
116117

117118
### Naming
118119

Sources/Algorithms/Chunked.swift

+17-2
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,9 @@ extension LazySequenceProtocol where Self: Collection, Elements: Collection {
410410
/// Returns a lazy collection of subsequences of this collection, chunked by
411411
/// the given predicate.
412412
///
413+
/// - Parameter belongInSameGroup: A closure that takes two adjacent elements
414+
/// of the sequence and returns whether or not they belong in the same group.
415+
///
413416
/// - Complexity: O(*n*), because the start index is pre-computed.
414417
@inlinable
415418
public func chunked(
@@ -422,7 +425,11 @@ extension LazySequenceProtocol where Self: Collection, Elements: Collection {
422425
}
423426

424427
/// Returns a lazy collection of subsequences of this collection, chunked by
425-
/// grouping elements that project to the same value.
428+
/// grouping elements that project to equal values.
429+
///
430+
/// - Parameter projection: A closure that takes an element in the sequence
431+
/// and returns an `Equatable` value that can be used to determine if adjacent
432+
/// elements belong in the same group.
426433
///
427434
/// - Complexity: O(*n*), because the start index is pre-computed.
428435
@inlinable
@@ -443,6 +450,10 @@ extension Collection {
443450
/// Returns a collection of subsequences of this collection, chunked by the
444451
/// given predicate.
445452
///
453+
/// - Parameter belongInSameGroup: A closure that takes two adjacent elements
454+
/// of the collection and returns whether or not they belong in the same
455+
/// group.
456+
///
446457
/// - Complexity: O(*n*), where *n* is the length of this collection.
447458
@inlinable
448459
public func chunked(
@@ -470,7 +481,11 @@ extension Collection {
470481
}
471482

472483
/// Returns a collection of subsequences of this collection, chunked by
473-
/// grouping elements that project to the same value.
484+
/// grouping elements that project to equal values.
485+
///
486+
/// - Parameter projection: A closure that takes an element in the collection
487+
/// and returns an `Equatable` value that can be used to determine if adjacent
488+
/// elements belong in the same group.
474489
///
475490
/// - Complexity: O(*n*), where *n* is the length of this collection.
476491
@inlinable

0 commit comments

Comments
 (0)