Letting RegExp method return something iterable?
rbuckton at chronicles.org
Wed Aug 28 17:32:50 PDT 2013
The advantage of a lazy execAll, is the ability to break out of the for..of loop without the need to continue to traverse the input string looking for matches. This is the same advantage that the `while(m = re.exec())` has going for it. You can always be greedy by using Array.from or an array comprehension if execAll is lazy, but you are back to using a while loop if execAll is greedy and you want lazy matching, which limits its usefulness in some scenarios.
Sent from my Windows Phone
From: Forbes Lindesay<mailto:forbes at lindesay.co.uk>
Sent: 8/28/2013 4:55 PM
To: Andrea Giammarchi<mailto:andrea.giammarchi at gmail.com>
Cc: Brendan Eich<mailto:brendan at mozilla.com>; es-discuss list<mailto:es-discuss at mozilla.org>; Erik Arvidsson<mailto:erik.arvidsson at gmail.com>
Subject: RE: Letting RegExp method return something iterable?
Right, I don’t care whether it’s lazy. I only care that it exists. Nobody’s crying out for a lazy version of string split (at least not yet anyway). I have had the issue of needing to loop over all the matches that a regular expression has. It is a common, recurring issue that many developers face.
Let’s move on from whether it should exist (clearly it should) and stick to whether it should be an array, or lazy. Does anyone have a strong opinion either way? The fact that all our regular expression iteration thus far has been lazy to me suggests this probably should be too, but maybe it would be simpler if it returned an array. I really hope someone will chime in on this.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss