[swift-dev] Starter project: API to upgrade AnySequence to Any*Collection

Austin Zheng austinzheng at gmail.com
Mon Dec 7 16:38:16 CST 2015


I'd be interested in taking it but I have another ticket already, so if
someone else wants it they should take it.

Austin

On Mon, Dec 7, 2015 at 2:35 PM, Dmitri Gribenko <gribozavr at gmail.com> wrote:

> On Mon, Dec 7, 2015 at 2:27 PM, Jacob Bandes-Storch <jtbandes at gmail.com>
> wrote:
> > What do you mean by "without copying the underlying collection"?
>
> The original collection should be preserved through this upgrade, and
> not, say, copied into a fresh Array.
>
> > Is this
> > specifically for the case where the AnySequence is wrapping a collection
> > (which is not always the case)?
>
> Exactly.
>
> Dmitri
>
> > On Mon, Dec 7, 2015 at 2:18 PM, Dmitri Gribenko via swift-dev
> > <swift-dev at swift.org> 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 <austinzheng at gmail.com>
> >> 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
> >> > <swift-dev at swift.org> 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 <gribozavr at gmail.com>*/
> >> >> _______________________________________________
> >> >> swift-dev mailing list
> >> >> swift-dev at swift.org
> >> >> 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 <gribozavr at gmail.com>*/
> >> _______________________________________________
> >> swift-dev mailing list
> >> swift-dev at swift.org
> >> 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 <gribozavr at gmail.com>*/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20151207/b63d9579/attachment.html>


More information about the swift-dev mailing list