Swift 2b2: Publish LazySequence’s base sequence to enable better type erasure

Originator:rix.rob
Number:rdar://21671142 Date Originated:03-Jul-2015 02:18 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode-beta (7A121l)
Classification:Enhancement Reproducible:Always
 
Summary:
LazySequence’s map and filter methods return LazySequence<MapSequenceView<S, U>> and LazySequence<FilterSequenceView<S>> respectively.

However, if you were to try to implement one of those outside of the standard library, you’d have to type them as LazySequence<MapSequenceView<LazySequence<S>, U>> and LazySequence<FilterSequenceView<LazySequence<S>>> respectively. The types in stdlib are pretty scary, but these are much, much worse.

This is because LazySequence doesn’t expose its underlying sequence in a public property, requiring third party extensions of it to pass the receiving LazySequence, rather than its underlying sequence, to the extending type.


Steps to Reproduce:
N/A

Expected Results:
N/A

Actual Results:
N/A

Regression:
N/A

Notes:
One could argue that ideal type erasure would come from returning AnySequence. Which is true enough, I suppose, but the standard library doesn’t do that with any of the type-erased protocols, with the sole exception of the reflection stuff. That leads a cautious individual to do as the standard library does, and have needlessly horrible return types in their interface as a result.

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!