[swift-evolution] About the PermutationGenerator

Jordan Rose jordan_rose at apple.com
Tue Jan 12 11:55:48 CST 2016

> On Jan 11, 2016, at 18:35 , plx via swift-evolution <swift-evolution at swift.org> wrote:
>> RandomElementSequence: As you say, this type is copyable, but its iteration is destructive: you can't get back to a previous state via any sort of Index. But that's not a distinction between Sequence and Generator today; there are some Generators that are perfectly copyable and others that are not. (Ideally, the ones that aren't would be made into classes.) If all you have is a generic Generator, you can only iterate it once…but the same is true of Sequence. Knowing the concrete type 
> ^ did something get edited out here?

Oops, yes. "Knowing the concrete type is the only way to guarantee that multiple iteration is safe." And then:

>> Sure, you could come up with a new protocol, MultipassSequence, but you could just as easily have a MultipassGenerator that just means "this generator is safe to copy". (That's basically InputIterator vs. ForwardIterator <http://en.cppreference.com/w/cpp/iterator> in C++.)


> It also highlights that `ForwardIndexType` and `GeneratorType` are suspiciously similar, and would be even more so in a “collections move indices” world (e.g. SR-122, which I hope is adopted in some form).

I guess this is true, in that both produce a single successor, but (a) ForwardIndexType is non-destructive whereas GeneratorType may be, and (b) in that new model, ForwardIndexType does not know its successor whereas GeneratorType does.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160112/429ca196/attachment.html>

More information about the swift-evolution mailing list