Re: sequence and iterables

On 11/15/13 9:17 PM, Jonas Sicking wrote:
> Can you give an example of when this is a problem. Snapshotting an
> iterable to me simply means iterating the iterator all the way through
> and remembering the data that it returned.

Sure.

It's just that no one normally working with iterables would do that.

> This is generally something that we want to do synchronously from the
> API before returning. Otherwise we need to defined exactly when the
> iterator is read. I can't think of any existing APIs that deal with
> array-like things and that doesn't iterate through the whole
> array-like before returning.

The typical way one would use an iterable is something like this:

   function f(iterable) {
     for (value of iterable) {
       doStuff(value);
     }
   }

whereas the snapshotting approach is more like:

   function f(iterable) {
     var snapshot = Array.from(iterable);
     for (value of snapshot) {
       doStuff(value);
     }
   }

which is slightly odd to do as the default thing with iterables...

-Boris

Received on Saturday, 16 November 2013 02:23:42 UTC