There is not enough documentation of the `Sequence` and `Generator` templates in the iBook or the online materials.
| Originator: | richardb | ||
| Number: | rdar://17210988 | Date Originated: | 2004/06/07 |
| Status: | Open | Resolved: | |
| Product: | Swift | Product Version: | |
| Classification: | Reproducible: |
Summary:
There is not enough documentation of the `Sequence` and `Generator` templates in the iBook or the online materials.
WWDC 2014 session 404 touched on this, but didn't fully explain it.
Consider a deck of cards, which could be Western, Mah Jong or something of the developer's own design:
struct Card {
enum Rank {
...
}
enum Suit {
...
}
let rank: Rank
let suit: Suit
static func fullDeck() -> Card[] {
var deck = Card[]()
for suit in Suit.all() {
for rank in Rank.all() {
let card = Card(rank: rank, suit: suit)
deck.append(card)
}
}
return deck
}
}
It is unclear to me how to write `Suit.all()` and `Rank.all()` in a generic way. I see tantalising hints re `EnumerateGenerator` in the standard library, but these are not documented.
Steps to Reproduce:
n/a
Expected Results:
Docs telling me how to use `EnumerateGenerator` etc to create a `static func all()` on my enums that returns all values.
Actual Results:
Left feeling that I'm missing something obvious.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!