W3C home > Mailing lists > Public > public-script-coord@w3.org > October to December 2013

Re: sequence and iterables

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Fri, 15 Nov 2013 21:23:09 -0500
Message-ID: <5286D70D.8050608@mit.edu>
To: Jonas Sicking <jonas@sicking.cc>
CC: "public-script-coord@w3.org" <public-script-coord@w3.org>, Anne van Kesteren <annevk@annevk.nl>
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

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:19 UTC