What do you mean by "without copying the underlying collection"? Is this specifically for the case where the AnySequence is wrapping a collection (which is not always the case)?
On Mon, Dec 7, 2015 at 2:18 PM, Dmitri Gribenko via swift-dev < [email protected]> wrote: > It would require a proposal and a review, but the implementation is > more challenging here than the API design. The proposal would be > trivial, just one extra API, if I'm imagining this correctly. > > Dmitri > > On Mon, Dec 7, 2015 at 2:10 PM, Austin Zheng <[email protected]> > wrote: > > Would this require a review/proposal, since it involves an API change? > > > > On Mon, Dec 7, 2015 at 2:08 PM, Dmitri Gribenko via swift-dev > > <[email protected]> wrote: > >> > >> Hi, > >> > >> If someone looks for a starter project in the standard library with > >> intermediate complexity (prior experience with Swift generics > >> required), here's one. > >> > >> This is in the area of existential sequence and collection wrappers. > >> > >> Upgrading AnyForwardCollection to AnyRandomAccessCollection works: > >> > >> (swift) AnyRandomAccessCollection(AnyForwardCollection([1,2,3])) > >> // r2 : AnyRandomAccessCollection<Int>? = > >> Optional(Swift.AnyRandomAccessCollection<Swift.Int>(_box: > >> Swift._CollectionBox<Swift.Array<Swift.Int>>)) > >> > >> Seems like we don't provide APIs to upgrade AnySequence to > Any*Collection: > >> > >> (swift) AnyRandomAccessCollection(AnySequence([1,2,3])) > >> <REPL Input>:1:1: error: cannot invoke initializer for type > >> 'AnyRandomAccessCollection<_>' with an argument list of type > >> '(AnySequence<Int>)' > >> > >> Of course, this should work without copying the underlying collection. > >> > >> https://bugs.swift.org/browse/SR-119 > >> > >> 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 <[email protected]>*/ > >> _______________________________________________ > >> swift-dev mailing list > >> [email protected] > >> https://lists.swift.org/mailman/listinfo/swift-dev > > > > > > > > -- > 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 <[email protected]>*/ > _______________________________________________ > swift-dev mailing list > [email protected] > https://lists.swift.org/mailman/listinfo/swift-dev >
_______________________________________________ swift-dev mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-dev
