Swift should provide a generic CollectionGenerator<T> struct to use when implementing Sequence

Originator:gordon
Number:rdar://17217478 Date Originated:07-Jun-2014 12:52 PM
Status:Open Resolved:
Product:Developer Tools Product Version:1
Classification:Enhancement Reproducible:Always
 
The most common implementation of an object that conforms to `Generate` is so generic, I can’t help but feel that it should be included in the standard library. As far as I can tell, this implementation should work 90% of the time:

```
struct CollectionGenerator<T>: Generator {
    var items: Slice<T>

    mutating func next() -> T? {
        if items.isEmpty { return nil }
        let ret = items[0]
        items = items[1..items.count]
        return ret
    }
}
```

This code is ripped almost verbatim from the Advanced Swift session video.

Steps to Reproduce:
When implementing `Sequence`, look for a basic object to use that conforms to `Generate`.

Expected Results:
An object is provided that handles the most common use case

Actual Results:
An object can’t be found, leading me to writing (or duplicating) code.

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!