@@ -248,18 +248,18 @@ extension Collection {
248
248
}
249
249
250
250
//===----------------------------------------------------------------------===//
251
- // chunks(of :)
251
+ // chunks(ofCount :)
252
252
//===----------------------------------------------------------------------===//
253
253
254
254
/// A collection that presents the elements of its base collection
255
- /// in `SubSequence` chunks of any given size .
255
+ /// in `SubSequence` chunks of any given count .
256
256
///
257
257
/// A `ChunkedByCount` is a lazy view on the base Collection, but it does not implicitly confer
258
258
/// laziness on algorithms applied to its result. In other words, for ordinary collections `c`:
259
259
///
260
- /// * `c.chunks(of : 3)` does not create new storage
261
- /// * `c.chunks(of : 3).map(f)` maps eagerly and returns a new array
262
- /// * `c.lazy.chunks(of : 3).map(f)` maps lazily and returns a `LazyMapCollection`
260
+ /// * `c.chunks(ofCount : 3)` does not create new storage
261
+ /// * `c.chunks(ofCount : 3).map(f)` maps eagerly and returns a new array
262
+ /// * `c.lazy.chunks(ofCount : 3).map(f)` maps lazily and returns a `LazyMapCollection`
263
263
public struct ChunkedByCount < Base: Collection > {
264
264
265
265
public typealias Element = Base . SubSequence
@@ -274,7 +274,7 @@ public struct ChunkedByCount<Base: Collection> {
274
274
internal var computedStartIndex : Index
275
275
276
276
/// Creates a view instance that presents the elements of `base`
277
- /// in `SubSequence` chunks of the given size .
277
+ /// in `SubSequence` chunks of the given count .
278
278
///
279
279
/// - Complexity: O(n)
280
280
@inlinable
@@ -305,11 +305,13 @@ extension ChunkedByCount: Collection {
305
305
}
306
306
}
307
307
308
+ /// - Complexity: O(n)
308
309
public var startIndex : Index { computedStartIndex }
309
310
public var endIndex : Index {
310
311
Index ( _baseRange: base. endIndex..< base. endIndex)
311
312
}
312
313
314
+ /// - Complexity: O(n)
313
315
public subscript( i: Index ) -> Element {
314
316
base [ i. baseRange]
315
317
}
@@ -376,9 +378,9 @@ where Base: RandomAccessCollection {
376
378
377
379
extension Collection {
378
380
/// Returns a `ChunkedCollection<Self>` view presenting the elements
379
- /// in chunks with count of the given size parameter.
381
+ /// in chunks with count of the given count parameter.
380
382
///
381
- /// - Parameter size: The size of the chunks. If the size parameter
383
+ /// - Parameter size: The size of the chunks. If the count parameter
382
384
/// is evenly divided by the count of the base `Collection` all the
383
385
/// chunks will have the count equals to size.
384
386
/// Otherwise, the last chunk will contain the remaining elements.
@@ -400,9 +402,21 @@ extension Collection {
400
402
401
403
// Conditional conformances.
402
404
extension ChunkedByCount : Equatable where Base: Equatable { }
403
- extension ChunkedByCount : Hashable where Base: Hashable , Base. Index: Hashable { }
405
+
406
+ // Since we have another stored property of type `Index` on the
407
+ // collection, synthetization of hashble conformace would require
408
+ // a `Base.Index: Hashable` constraint, so we implement the hasher
409
+ // only in terms of base. Since the computed index is based on it,
410
+ // it should make a difference here.
411
+ extension ChunkedByCount : Hashable where Base: Hashable {
412
+ public func hash( into hasher: inout Hasher ) {
413
+ hasher. combine ( base)
414
+ }
415
+ }
404
416
extension ChunkedByCount . Index : Hashable where Base. Index: Hashable { }
405
417
406
418
// Lazy conditional conformance.
407
- extension ChunkedByCount : LazySequenceProtocol where Base: LazySequenceProtocol { }
408
- extension ChunkedByCount : LazyCollectionProtocol where Base: LazyCollectionProtocol { }
419
+ extension ChunkedByCount : LazySequenceProtocol
420
+ where Base: LazySequenceProtocol { }
421
+ extension ChunkedByCount : LazyCollectionProtocol
422
+ where Base: LazyCollectionProtocol { }
0 commit comments