Skip to content

Commit abc5559

Browse files
author
Tim Vermeulen
authored
Remove collection conformances to Equatable and Hashable (#124)
1 parent bcdbac8 commit abc5559

File tree

14 files changed

+2
-209
lines changed

14 files changed

+2
-209
lines changed

Guides/Compacted.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ extension Collection {
3131
```
3232

3333
One is a more general `CompactedSequence` for any `Sequence` base. And the other a more specialized `CompactedCollection`
34-
where base is a `Collection` and with conditional conformance to `BidirectionalCollection`, `RandomAccessCollection`,
35-
`LazyCollectionProtocol`, `Equatable` and `Hashable` when base collection conforms to them.
34+
where base is a `Collection` and with conditional conformance to `BidirectionalCollection`, `RandomAccessCollection` and
35+
`LazyCollectionProtocol` when base collection conforms to them.
3636

3737
### Naming
3838

Sources/Algorithms/Chain.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,6 @@ extension Chain2: BidirectionalCollection
283283
extension Chain2: RandomAccessCollection
284284
where Base1: RandomAccessCollection, Base2: RandomAccessCollection {}
285285

286-
extension Chain2: Equatable where Base1: Equatable, Base2: Equatable {}
287-
extension Chain2: Hashable where Base1: Hashable, Base2: Hashable {}
288-
289286
//===----------------------------------------------------------------------===//
290287
// chain(_:_:)
291288
//===----------------------------------------------------------------------===//

Sources/Algorithms/Chunked.swift

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -512,21 +512,6 @@ extension Collection {
512512
}
513513
}
514514

515-
// Conditional conformances.
516-
extension ChunkedByCount: Equatable where Base: Equatable {}
517-
518-
// Since we have another stored property of type `Index` on the
519-
// collection, synthesis of `Hashble` conformace would require
520-
// a `Base.Index: Hashable` constraint, so we implement the hasher
521-
// only in terms of `base` and `chunkCount`. Since the computed
522-
// index is based on it, it should not make a difference here.
523-
extension ChunkedByCount: Hashable where Base: Hashable {
524-
@inlinable
525-
public func hash(into hasher: inout Hasher) {
526-
hasher.combine(base)
527-
hasher.combine(chunkCount)
528-
}
529-
}
530515
extension ChunkedByCount.Index: Hashable where Base.Index: Hashable {}
531516

532517
// Lazy conditional conformance.

Sources/Algorithms/Combinations.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,6 @@ extension Combinations: Sequence {
181181
}
182182

183183
extension Combinations: LazySequenceProtocol where Base: LazySequenceProtocol {}
184-
extension Combinations: Equatable where Base: Equatable {}
185-
extension Combinations: Hashable where Base: Hashable {}
186184

187185
//===----------------------------------------------------------------------===//
188186
// combinations(ofCount:)

Sources/Algorithms/Compacted.swift

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -179,48 +179,3 @@ extension CompactedCollection: LazySequenceProtocol
179179
where Base: LazySequenceProtocol {}
180180
extension CompactedCollection: LazyCollectionProtocol
181181
where Base: LazyCollectionProtocol {}
182-
183-
184-
// Hashable and Equatable conformance are based on each non-nil
185-
// element on base collection.
186-
extension CompactedSequence: Equatable
187-
where Base.Element: Equatable {
188-
189-
@inlinable
190-
public static func ==(lhs: CompactedSequence,
191-
rhs: CompactedSequence) -> Bool {
192-
lhs.elementsEqual(rhs)
193-
}
194-
}
195-
196-
extension CompactedSequence: Hashable
197-
where Element: Hashable {
198-
199-
@inlinable
200-
public func hash(into hasher: inout Hasher) {
201-
for element in self {
202-
hasher.combine(element)
203-
}
204-
}
205-
}
206-
207-
extension CompactedCollection: Equatable
208-
where Base.Element: Equatable {
209-
210-
@inlinable
211-
public static func ==(lhs: CompactedCollection,
212-
rhs: CompactedCollection) -> Bool {
213-
lhs.elementsEqual(rhs)
214-
}
215-
}
216-
217-
extension CompactedCollection: Hashable
218-
where Element: Hashable {
219-
220-
@inlinable
221-
public func hash(into hasher: inout Hasher) {
222-
for element in self {
223-
hasher.combine(element)
224-
}
225-
}
226-
}

Sources/Algorithms/Cycle.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,6 @@ extension FiniteCycle: BidirectionalCollection
163163
extension FiniteCycle: RandomAccessCollection
164164
where Base: RandomAccessCollection {}
165165

166-
extension FiniteCycle: Equatable where Base: Equatable {}
167-
extension FiniteCycle: Hashable where Base: Hashable {}
168-
169166
//===----------------------------------------------------------------------===//
170167
// cycled()
171168
//===----------------------------------------------------------------------===//

Sources/Algorithms/Indexed.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ extension Indexed: BidirectionalCollection where Base: BidirectionalCollection {
7272
extension Indexed: RandomAccessCollection where Base: RandomAccessCollection {}
7373
extension Indexed: LazySequenceProtocol where Base: LazySequenceProtocol {}
7474
extension Indexed: LazyCollectionProtocol where Base: LazyCollectionProtocol {}
75-
extension Indexed: Equatable where Base: Equatable {}
76-
extension Indexed: Hashable where Base: Hashable {}
7775

7876
//===----------------------------------------------------------------------===//
7977
// indexed()

Sources/Algorithms/Product.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,6 @@ extension Product2: RandomAccessCollection
438438
where Base1: RandomAccessCollection, Base2: RandomAccessCollection {}
439439

440440
extension Product2.Index: Hashable where Base1.Index: Hashable, Base2.Index: Hashable {}
441-
extension Product2: Equatable where Base1: Equatable, Base2: Equatable {}
442-
extension Product2: Hashable where Base1: Hashable, Base2: Hashable {}
443441

444442
//===----------------------------------------------------------------------===//
445443
// product(_:_:)

Sources/Algorithms/Stride.swift

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -269,22 +269,4 @@ extension StrideCollection: BidirectionalCollection
269269
}
270270

271271
extension StrideCollection: RandomAccessCollection where Base: RandomAccessCollection {}
272-
273-
extension StrideCollection: Equatable where Base.Element: Equatable {
274-
@inlinable
275-
public static func == (lhs: StrideCollection, rhs: StrideCollection) -> Bool {
276-
lhs.elementsEqual(rhs, by: ==)
277-
}
278-
}
279-
280-
extension StrideCollection: Hashable where Base.Element: Hashable {
281-
@inlinable
282-
public func hash(into hasher: inout Hasher) {
283-
hasher.combine(stride)
284-
for element in self {
285-
hasher.combine(element)
286-
}
287-
}
288-
}
289-
290272
extension StrideCollection.Index: Hashable where Base.Index: Hashable {}

Sources/Algorithms/Windows.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,4 @@ extension Windows: BidirectionalCollection where Base: BidirectionalCollection {
350350
extension Windows: LazySequenceProtocol where Base: LazySequenceProtocol {}
351351
extension Windows: LazyCollectionProtocol where Base: LazyCollectionProtocol {}
352352
extension Windows: RandomAccessCollection where Base: RandomAccessCollection {}
353-
extension Windows: Equatable where Base: Equatable {}
354-
extension Windows: Hashable where Base: Hashable, Base.Index: Hashable {}
355353
extension Windows.Index: Hashable where Base.Index: Hashable {}

0 commit comments

Comments
 (0)