Letting RegExp method return something iterable?

Axel Rauschmayer axel at rauschma.de
Wed Aug 28 08:02:00 PDT 2013


>> I'm guessing that code like:
>> 
>> ```js
>> var matches = /foo/.execMultipleLazy('str')
>> for (let match of matches) {
>>  //do something
>> }
>> for (let match of matches) {
>>  //do something
>> }
>> for (let match of matches) {
>>  //do something
>> }
>> ```
>> 
>> Would go wrong somehow

> Yes.  This is a standard Python issue - if you want to make sure you
> can loop over something twice, regardless of whether it's an array or
> an iterator, just pass it through list() first.
> 
> Similarly, in JS you'd just pass it through Array.from() first.


Additional option:

```js
var arrayOfMatches = [ .../foo/.execMultipleLazy('str') ]
```

-- 
Dr. Axel Rauschmayer
axel at rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130828/c8b44b96/attachment-0001.html>


More information about the es-discuss mailing list