Swift 4.1
Swift 4.1 adds more generics features to the language, furthering the goals set out in the Swift Generics Manifesto. The following generics-related proposals have been implemented in this release:
- SE-0143 Conditional Conformance
- SE-0157 Support recursive constraints on associated types
- SE-0185 Synthesizing Equatable and Hashable conformance
- SE-0187 Introduce Sequence.compactMap(_:)
- SE-0188 Make Standard Library Index Types Hashable
- SE-0191 Eliminate IndexDistance from Collection
[…]
These are additional Swift Evolution proposals that were implemented in this release:
This was a fun update because it was easy to update my code, and I was able to delete lots of boilerplate related to Equatable
and IndexDistance
. Synthesized Equatable
and Hashable
conformance makes the code much more concise and potentially more reliable. It still has some room for improvement, though: there’s no way to omit fields without implementing the methods yourself, and the internal function for combining hash values is not exposed as API.
See also: Replacing flatMap With compactMap.
Previously: Swift 4: Synthesizing Equatable and Hashable Conformance, Swift 4.1 Conditional Conformance Is Amazing, Code Size Optimization Mode in Swift 4.1.
Update (2018-04-03): Ben Cohen:
Hashing needed some more work before this could happen, but @lorentey has been working on a proposal to turn the hashing improvements he landed in 4.2 into a proposal for a public API.
See also: Accidentally Quadratic Rust Hash Tables.
Update (2018-04-12): Joe Groff (tweet):
The core team discussed this proposal in our meeting today. There are still a couple days left in the review period, but we’re tentatively inclined to accept this proposal, but wanted to suggest some changes based on public review discussion and our own review[…]