Swift 中的多遍序列是什么?

What is a multi-pass Sequence in Swift?

我正在查看 Swift GeneratorType 文档中的 this language,但我很难理解它:

Any code that uses multiple generators (or for...in loops) over a single sequence should have static knowledge that the specific sequence is multi-pass, either because its concrete type is known or because it is constrained to CollectionType. Also, the generators must be obtained by distinct calls to the sequence's generate() method, rather than by copying.

序列为 "multi-pass" 是什么意思?这种语言似乎很重要,但我找不到很好的解释。例如,我理解 "multi-pass compiler" 的概念,但我不确定这些概念是否相似或相关...

此外,我搜索了 SO 以寻找其他回答此问题的帖子。我发现 this one,它在 C++ 上下文中作出以下声明:

The difference between algorithms that copy their iterators and those that do not is that the former are termed "multipass" algorithms, and require their iterator type to satisfy ForwardIterator, while the latter are single-pass and only require InputIterator.

但是我也不是很清楚这个意思,我不确定Swift中的概念是否相同。

任何比我聪明的人的见解都将不胜感激。

一个 "multi-pass" 序列可以通过 for...in 循环或使用任意数量的生成器(通过 生成())

文本解释了你会知道一个序列是多遍的,因为你

  • 知道它的类型(可能是你设计的class)或者
  • 知道它符合 CollectionType。 (例如,集合和数组)