Letting RegExp method return something iterable?
dean at deanlandolt.com
Thu Aug 29 07:11:03 PDT 2013
On Thu, Aug 29, 2013 at 4:13 AM, Brendan Eich <brendan at mozilla.com> wrote:
> Axel Rauschmayer wrote:
>> * /g flag must be set
>> * lastIndex must be 0
>> * can’t inline the regex, because it is needed as a pseudo-iterator (more
>> of an anti-pattern, anyway, but still)
>> * side effects via lastIndex may be a problem
> Anything we do of the execAll/execIter kind had better be immune to the
> awful Perl4-infused "mutable lastIndex state but only if global" kind.
> Compositionality required.
> The design decision to face is what to do when a global regexp is used.
> Throw, or ignore its lastIndex?
I'd hate to see it throw. Ignoring lastIndex seems friendlier, especially
if it were called `execAll`. It probably shouldn't be called `execIter`
considering `exec` is already an iterator (even if a bit crazy).
I'd love to be able to `send` a specific index to the generator, which
would be completely equivalent to `RegExp.prototype.exec` without the
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss