[swift-evolution] [RFC] New collections model: collections advance indices

Dmitri Gribenko gribozavr at gmail.com
Thu Mar 3 15:28:01 CST 2016


On Thu, Mar 3, 2016 at 9:56 AM, plx via swift-evolution
<swift-evolution at swift.org> wrote:
> # General Remarks: Great!
>
> Thanks for sharing this proposal; it's a big change, but will be a big improvement once it's in place, and it's encouraging to see the team is willing to undertake changes of such scale.
>
> I'm not sure how much discussion you'll actually manage to scare up b/c the issues this proposal addresses are *not* common, but are nevertheless rather significant when encountered.
>
> E.G.: it's nice to be able to create simple chain/product/etc. collection-combinators which can, themselves, be collections, without winding up with indices indices forced to choose between *either* holding a back-reference to retrieve various startIndex/endIndex values as-needed *or* carrying around a complete set of all needed startIndex/endIndex values.

Agreed!  We already have that problem in the lazy flatMap collection.

> I don’t have any negative feedback that isn’t subsumed by the next section.
>
> # Concern: Linearity Baked-In
>
> Even with this change, I have some concern that the proposed protocol hierarchy from `Collection` onward feels like it has a foreseeable lack of generality due to how strongly "linear" the design wants `Collection` to be.
>
> Is this the right time to raise such concerns (e.g. in-scope for this discussion)?

We can definitely dive into more details about this.  One thing that I
would want to understand is whether this non-linearity concept could
be added later without a re-design.

Could you provide more information about the linearity issues that you
have in mind?  Are you thinking of something like Segmented Iterators
and Hierarchical Algorithms [1]?

[1] http://lafstern.org/matt/segmented.pdf

> Other than that concern about generality I think this proposal looks great "on paper” and I hope to get a chance to experiment with it soon.

If you want to try an early version, there is a prototype
implementation in
https://github.com/apple/swift/blob/master/test/Prototypes/CollectionsMoveIndices.swift

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/


More information about the swift-evolution mailing list