jjzjj

Iterable

全部标签

javascript - 将 iterable 中的前 N ​​项转换为数组

类似于问题ConvertES6IterabletoArray的内容.但我只想要前N项。有没有内置的功能可以让我这样做?或者我怎样才能更优雅地实现这一目标?letN=100;function*Z(){for(leti=0;;i++)yieldi;}//Thiswontwork//Array.from(Z()).slice(0,N);//[...Z()].slice(0,N)//Thisworks,butabuilt-inmaybepreferredleta=[],t=Z();for(leti=0;i 最佳答案 要获取iterator的

javascript - 为什么 Javascript `iterator.next()` 返回一个对象?

帮助!在用C#编程了很长一段时间后,我开始喜欢上Javascript,但我一直在学习喜欢可迭代协议(protocol)!为什么Javascript采用protocol需要为每次迭代创建一个新对象?为什么有next()返回一个属性为done的新对象和value而不是采用像C#IEnumerable这样的协议(protocol)和IEnumerator它以需要两次调用为代价不分配任何对象(一次调用moveNext以查看迭代是否完成,第二次调用current以获取值)?是否有底层优化跳过由next()返回的对象的分配??很难想象,因为iterable不知道返回后如何使用该对象...生成器似乎

javascript - HTMLCollections 可以用 for...of (Symbol.iterator) 迭代吗?

DOM4使NodeList可迭代:interfaceNodeList{getterNode?item(unsignedlongindex);readonlyattributeunsignedlonglength;iterableNode>;};根据WebIDL,这意味着Objectsimplementinganinterfacethatisdeclaredtobeiterablesupportbeingiteratedovertoobtainasequenceofvalues.Note:IntheECMAScriptlanguagebinding,aninterfacethatisit

javascript - 在 ES6 之前的 Typescript 中实现 Iterator<T> 的推荐方法

这个问题在这里已经有了答案:typescript:makeclassobjectsiterable(3个答案)关闭5年前。我有一个项目,其中包含许多理想情况下会实现Iterable的类和/或Iterator接口(interface)。但是我似乎找不到这些接口(interface)的标准TypeScript定义(例如在typescript-collections或一些类似的包中)。我知道这些在ECMAScript6中通过Symbol.iterator有所标准化。机制,但我的目标是ECMAScript5,并且在可预见的future将保持不变。我能否以某种方式获得这些接口(interface

javascript - Apollo "Subscription field must return Async Iterable. Received: undefined"

我有一个触发channel事件“countIncr”的突变,但我没有看到事件的相应订阅与事件负载一起触发。更新:我已经对这篇文章进行了多次更新,现在我正在更改标题以更能代表我所在的位置。我收到graphqlPlayground错误"SubscriptionfieldmustreturnAsyncIterable.Received:undefined"我遇到问题的TGRstack复制:https://github.com/TGRstack/tgr-apollo-subscription-example-microservice/没有TGRstack的工作再现:https://github

Python openpyxl load_workbook 错误 : TypeError (NoneType not Iterable) and ValueError (Max. 值为 180)

所以我在WindowsXP笔记本电脑上安装了Python3.4.1。我得到了openpyxl包(现在不记得是哪个版本了,我想是2.1),我一直在努力,编写自定义代码来根据我工作场所的需要修改Excel文档。然后我格式化了我的笔记本电脑(出于工作原因)并安装了Windows7。我再次掌握了Python3.4.1。我pip安装了openpyxl(在我的命令提示符中显示“pipinstallopenpyxl”)——这次绝对是2.1版。然后,我尝试打开我以前的一些工作簿。这是在IDLEGUI界面中-不是在脚本或任何东西中。我只是输入(在正确导入openpyxl->load_workbook之后

Windows 中的 Python h2o : cannot initialize (TypeError: argument of type 'NoneType' is not iterable)

我正在尝试在我的公司使用pythonh2o。使用命令后:>importh2o>h2o.init()我得到了h2o\connection.py:110:UserWarning:Proxyenvironmentvariable`HTTP_PROXY`withvalue`http://username:password@proxy.**.com:8080`found.ThismayinterferewithyourH2OConnection.warnings.warn("Proxyenvironmentvariable`"+name+"`withvalue`"+value+"`found.T

javascript - 如何知道何时在动态 "iterable"参数中解决所有 Promises?

我的问题是我不知道如何知道动态promise数组何时解决了所有promise。举个例子:varpromiseArray=[];promiseArray.push(newPromise(){/*blablabla*/});promiseArray.push(newPromise(){/*blablabla*/});Promise.all(promiseArray).then(function(){//Thiswillbeexecutenwhenthose2promisesaresolved.});promiseArray.push(newPromise(){/*blablabla*/})

javascript - react - Redux 应用程序 : "Invalid attempt to spread non-iterable instance" Issue

Atthebeginning,thatsampleappwasworkingproperly.IcouldseedatathatIinputtedoverbrowserpageanddatabase.Atnow,Icanseethedataonlyviathedatabase,thebrowserdoesn'tshowdataandgettingthiserroradditionally:"Invalidattempttospreadnon-iterableinstance".有示例代码:projectActions.jsimport{FETCH_BOOK,CREATE_BOOK,DE

php - 什么是 PHP 中的 Iterables 以及我们为什么使用它?

我刚刚从PHP7.1文档中听说了Iterables。但是没有得到它的实际用例,而且这个概念对我来说也不清楚。那么任何人都可以用一些简单的例子来解释它以更快地获取它吗?我想知道为什么以及在哪里使用它?可迭代的好处是什么? 最佳答案 这可能会有所帮助wiki.php.net/rfc/iterableiterable的主要优点是可以将类、方法或函数参数声明为iterable但不必关心实现,即数组、迭代器、生成器、等等。所以任何可迭代的东西都可以使用。 关于php-什么是PHP中的Iterabl