问题标签 [iterator-protocol]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
139 浏览

javascript - ES6 RegExps 会支持 Iterator 协议吗?

我无法在规范提案列表中找到关于ES6 中的 RegExps 是否会提供必要的方法来支持匹配组的迭代器协议的答案。有许多符号方法,但我对各种符号的语义还不够熟悉,无法判断它们是否会提供这种方法。

我会想象这样的事情:

这似乎在 6to5 的 REPL 中有效,记录了预期的"test string", "string", "string".

这是在 ES6 规范中具体定义的,如果没有,正则表达式结果的哪些属性允许它工作?或者它只是 6to5 不完全是 ES6 的产物?

0 投票
1 回答
200 浏览

swift - 为什么变异函数 next 在迭代后不会改变结构(符合 Sequence 和 IteratorProtocol)?

IteratorProtocol我编写了一个堆栈结构,并使其符合Sequence协议。next函数正在变异。所以我想堆栈的迭代会改变结构。

这是控制台输出: 在此处输入图像描述

我不明白为什么堆栈没有改变。我想在变异next()调用之后它会变空。

0 投票
1 回答
64 浏览

ios - How to detect the first run of an IteratorProtocol in swift?

Trying to detect the first run of an Iterator protocol. In the example below I'm trying to start printing Fibonacci series from Zero but it starts from One:

What modifications can be made to the above code to detect the first run?

0 投票
2 回答
82 浏览

python - 使用迭代器协议生成素数

我试图得到一系列从 1 到 n 的素数。我没有使用范围和 for 循环,而是尝试使用迭代器协议来实现它。到目前为止,我有以下内容,但正如您将看到的,它并没有达到我的预期。

它打印 2,3,5,5,7,7 目标是打印 2,3,5,7,11...19

我只是不想回答,如果您也可以解释一下,我将不胜感激。谢谢