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

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


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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20151207/206bcb27/attachment.html>


More information about the swift-dev mailing list