From bfcaaa8758d6d5d4ea44486365c79b5271e0b0a6 Mon Sep 17 00:00:00 2001 From: Matt Zanchelli Date: Wed, 2 Aug 2023 08:18:17 -0700 Subject: [PATCH] Correct Chunked documentation (#182) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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` --- Guides/Chunked.md | 3 ++- Sources/Algorithms/Chunked.swift | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Guides/Chunked.md b/Guides/Chunked.md index a2f6703..583f781 100644 --- a/Guides/Chunked.md +++ b/Guides/Chunked.md @@ -112,7 +112,8 @@ collection is bidirectional. `ChunksOfCountCollection` and ### Complexity -The eager methods are O(_n_), the lazy methods are O(_1_). +The eager methods are O(_n_) where _n_ is the number of elements in the +collection. The lazy methods are O(_n_) because the start index is pre-computed. ### Naming diff --git a/Sources/Algorithms/Chunked.swift b/Sources/Algorithms/Chunked.swift index 48839a2..52efbd0 100644 --- a/Sources/Algorithms/Chunked.swift +++ b/Sources/Algorithms/Chunked.swift @@ -410,6 +410,9 @@ extension LazySequenceProtocol where Self: Collection, Elements: Collection { /// Returns a lazy collection of subsequences of this collection, chunked by /// the given predicate. /// + /// - Parameter belongInSameGroup: A closure that takes two adjacent elements + /// of the sequence and returns whether or not they belong in the same group. + /// /// - Complexity: O(*n*), because the start index is pre-computed. @inlinable public func chunked( @@ -422,7 +425,11 @@ extension LazySequenceProtocol where Self: Collection, Elements: Collection { } /// Returns a lazy collection of subsequences of this collection, chunked by - /// grouping elements that project to the same value. + /// grouping elements that project to equal values. + /// + /// - Parameter projection: A closure that takes an element in the sequence + /// and returns an `Equatable` value that can be used to determine if adjacent + /// elements belong in the same group. /// /// - Complexity: O(*n*), because the start index is pre-computed. @inlinable @@ -443,6 +450,10 @@ extension Collection { /// Returns a collection of subsequences of this collection, chunked by the /// given predicate. /// + /// - Parameter belongInSameGroup: A closure that takes two adjacent elements + /// of the collection and returns whether or not they belong in the same + /// group. + /// /// - Complexity: O(*n*), where *n* is the length of this collection. @inlinable public func chunked( @@ -470,7 +481,11 @@ extension Collection { } /// Returns a collection of subsequences of this collection, chunked by - /// grouping elements that project to the same value. + /// grouping elements that project to equal values. + /// + /// - Parameter projection: A closure that takes an element in the collection + /// and returns an `Equatable` value that can be used to determine if adjacent + /// elements belong in the same group. /// /// - Complexity: O(*n*), where *n* is the length of this collection. @inlinable