On Fri, May 6, 2016 at 12:53 AM, Nate Cook <[email protected]> wrote:
> That brings up the question of which protocol to add the requirement to?
> Without a MutableBidirectionalProtocol (which we don't want, right?), we'd
> need to add it to MutableCollection. While a mutating reverse() is possible
> for a forward collection, it has significant space complexity, since it
> works either by creating an array of the indices or through recursion. We
> would also have reverse() available on some collections that don't have
> reversed(). Does that sound alright?
Good question! I don't think we should provide reverse() on forward
collections.
I think we can play some tricks here. We can add an underscored
_customReverse() requirement to MutableCollection, a default
implementation that traps, and two specialized implementations for
forward and bidirectional collections. We would then add a protocol
extension (not a requirement) reverse() on MutableCollection where
Self : BidirectionalCollection that will call _customReverse().
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-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution