From dca25448e0141b9739c22c66b2d1e25adda06c00 Mon Sep 17 00:00:00 2001 From: Tim Vermeulen Date: Wed, 7 Apr 2021 16:43:37 +0200 Subject: [PATCH] Rename the `LazyChunked` type to `Chunked` (#121) * Rename LazyChunked -> Chunked * Add deprecated typealias for `LazyChunked` --- Guides/Chunked.md | 6 +++--- Sources/Algorithms/Chunked.swift | 19 +++++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Guides/Chunked.md b/Guides/Chunked.md index 72f8dd0..2b5444c 100644 --- a/Guides/Chunked.md +++ b/Guides/Chunked.md @@ -76,15 +76,15 @@ extension Collection { extension LazyCollectionProtocol { public func chunked( by belongInSameGroup: @escaping (Element, Element) -> Bool - ) -> LazyChunked + ) -> Chunked public func chunked( on projection: @escaping (Element) -> Subject - ) -> LazyChunked + ) -> Chunked } ``` -The `LazyChunked` type is bidirectional when the wrapped collection is +The `Chunked` type is bidirectional when the wrapped collection is bidirectional. ### Complexity diff --git a/Sources/Algorithms/Chunked.swift b/Sources/Algorithms/Chunked.swift index e64fde8..1257359 100644 --- a/Sources/Algorithms/Chunked.swift +++ b/Sources/Algorithms/Chunked.swift @@ -11,7 +11,7 @@ /// A collection wrapper that breaks a collection into chunks based on a /// predicate or projection. -public struct LazyChunked { +public struct Chunked { /// The collection that this instance provides a view onto. @usableFromInline internal let base: Base @@ -45,7 +45,7 @@ public struct LazyChunked { } } -extension LazyChunked: LazyCollectionProtocol { +extension Chunked: LazyCollectionProtocol { /// A position in a chunked collection. public struct Index: Comparable { /// The range corresponding to the chunk at this position. @@ -106,9 +106,9 @@ extension LazyChunked: LazyCollectionProtocol { } } -extension LazyChunked.Index: Hashable where Base.Index: Hashable {} +extension Chunked.Index: Hashable where Base.Index: Hashable {} -extension LazyChunked: BidirectionalCollection +extension Chunked: BidirectionalCollection where Base: BidirectionalCollection { /// Returns the index in the base collection of the start of the chunk ending @@ -131,6 +131,9 @@ extension LazyChunked: BidirectionalCollection } } +@available(*, deprecated, renamed: "Chunked") +public typealias LazyChunked = Chunked + //===----------------------------------------------------------------------===// // lazy.chunked(by:) //===----------------------------------------------------------------------===// @@ -143,8 +146,8 @@ extension LazyCollectionProtocol { @inlinable public func chunked( by belongInSameGroup: @escaping (Element, Element) -> Bool - ) -> LazyChunked { - LazyChunked( + ) -> Chunked { + Chunked( base: elements, projection: { $0 }, belongInSameGroup: belongInSameGroup) @@ -157,8 +160,8 @@ extension LazyCollectionProtocol { @inlinable public func chunked( on projection: @escaping (Element) -> Subject - ) -> LazyChunked { - LazyChunked( + ) -> Chunked { + Chunked( base: elements, projection: projection, belongInSameGroup: ==)