Letting RegExp method return something iterable?

Andrea Giammarchi andrea.giammarchi at gmail.com
Mon Aug 26 17:52:56 PDT 2013


to be really honest, most people will get it wrong regardless since thanks
to JSLint and friends they are use to declare everything on top and they
probably forgot for accepts `var` declarations.

I've never ever needed this syntax and I don't see the miracle. I am sure
somebody one day will use that but I am just worried that resources will be
wasted to add methods nobody needed that much 'till now instead of focusing
on things that we cannot even write in one line of code as Alex did.

Just my 2 cents on this topic, no hard feelings on the proposal itself.


On Mon, Aug 26, 2013 at 5:30 PM, Forbes Lindesay <forbes at lindesay.co.uk>wrote:

>  `String#split` already is iterable because it returns an array.  What it
> isn't is **lazy**.
>
>  To be equivalent to the for code, the let needs to go inside the body of
> the while, not outside.  This neatly demonstrates the key point:
>
>   - as it stands, writing this kind of code tends to be bug prone (i.e.
> people get it wrong in confusing ways)
>  - it would be less bug prone if there was just a method that returned an
> iterable.  That _could_ be an Array, rather than a lazy collection.
>
> On 27 Aug 2013, at 01:20, "Andrea Giammarchi" <andrea.giammarchi at gmail.com>
> wrote:
>
>   ```javascript
> {let m; while(m = re.exec(str)) {
>   // ... no, really
> }}
> ```
>  I don't get the need of this but if this is the trend then String#split
> needs an iterable too (no!)
>
>
>
>
> On Mon, Aug 26, 2013 at 4:23 PM, Brendan Eich <brendan at mozilla.com> wrote:
>
>> Andrea Giammarchi wrote:
>>
>>> Is it very useful because you wrote for instead of while ?
>>>
>>> ```javascript
>>> while (m = re.exec(str))
>>>   console.log(m[0])
>>> ;
>>> ```
>>>
>>
>>  It is, for two reasons:
>>
>> 1. in JS only for can have a let or var binding in the head.
>>
>> 2. the utility extends to all for-of variations: array comprehensions,
>> generator expresisons.
>>
>> /be
>>
>
>   _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130826/c03603a3/attachment.html>


More information about the es-discuss mailing list