swift-book icon indicating copy to clipboard operation
swift-book copied to clipboard

Document default types for associated values

Open natecook1000 opened this issue 7 years ago • 2 comments

Previous ID SR-8761
Radar None
Original Reporter @natecook1000
Type Improvement

Additional Detail from JIRA
Votes 0
Component/s
Labels Improvement
Assignee None
Priority Medium

md5: 5483446fdf4d37083296d04e708f33f2

Issue Description:

We don't appear to document the way you can provide a default type in an associate's type declaration. Noted in https://forums.swift.org/t/a-question-about-associatedtype-in-protocols/16168

natecook1000 avatar Sep 15 '18 14:09 natecook1000

This is used quite a fair bit in the standard library for doing things like providing a default implementation of a Collection's Slice type

associatedtype SubSequence : Collection = Slice<Self> where Self.Element == Self.SubSequence.Element, Self.SubSequence == Self.SubSequence.SubSequence

It seems strange that a really useful and used (at least in std lib) isn't documented at all in the Swift book

schwa avatar Oct 05 '22 04:10 schwa

Now that TSPL is open source, I've opened https://github.com/apple/swift-book/issues/40 to track this issue.

natecook1000 avatar Oct 05 '22 15:10 natecook1000