Andrea Giammarchi (2013-08-27T01:48:25.000Z)
one lazy hilarious thought on that though ...


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**.
>
> <https://mail.mozilla.org/listinfo/es-discuss>
>
>
it's straight forward to make String#split(re) lazy using the `lastIndex`
indeed:

```javascript

function* lazySplit(str, re) {
  for (var
    i = 0;
    re.test(str);
    i = re.lastIndex
  )
    yield str.slice(
      i, re.lastIndex - RegExp.lastMatch.length
    )
  ;
  yield str.slice(i);
}

```

There,
    Best Regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130826/f7a53881/attachment.html>
domenic at domenicdenicola.com (2013-09-08T00:18:37.757Z)
one lazy hilarious thought on that though ...


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**.

it's straight forward to make String#split(re) lazy using the `lastIndex`
indeed:

```javascript

function* lazySplit(str, re) {
  for (var
    i = 0;
    re.test(str);
    i = re.lastIndex
  )
    yield str.slice(
      i, re.lastIndex - RegExp.lastMatch.length
    )
  ;
  yield str.slice(i);
}

```