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 <griboz...@gmail.com>*/
_______________________________________________
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev

Reply via email to