Git Product home page Git Product logo

Comments (5)

arv avatar arv commented on May 3, 2024

From [email protected] on June 23, 2012 20:24:02
var arr = [x for x of generator]

from traceur-compiler.

arv avatar arv commented on May 3, 2024

From [email protected] on June 25, 2012 03:12:36
Oh, is harmony getting array comprehensions? That's awesome! If so, I agree that a separate function isn't really needed. I was afraid I'd have to write something ugly like:

var arr = [];
for (var x of generator) {
arr.push(x);
}

I guess the larger question here is: will generators get the nice Array.prototype functions like map, reduce, filter, any, some etc (https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/prototype)? It'd be nice to be able to do things like "generator.map((x) => x + 1)" ... if all of the nice functions work then conversion becomes less important.

Although even then, I guess you can get pretty far with just comprehensions!

from traceur-compiler.

arv avatar arv commented on May 3, 2024

From [email protected] on June 25, 2012 04:23:29
Generator and Array comprehensions are in the latest ES6 draft (generator one is not complete). I added support for it in Traceur last week.

Firefox makes all generators/iterators share the same prototype. It is not available by name but you can get to it by getting the constructor of a iterator.

function g() { yield 42 }
g().constructor.prototype.map = function(f) {
for (let item of this) {
yield f(item);
}
};

function h() { yield 1; yield 2 }
i = h().map(function(item) { return item * item })
[x for (x of i)] // SpiderMonkey syntax is not compatible with ES6

Traceur does not share the prototype. We should probably fix that.

from traceur-compiler.

arv avatar arv commented on May 3, 2024

Closing this since ES6 had [...iterable] even though that might be deferred to ES7 :'(

from traceur-compiler.

arv avatar arv commented on May 3, 2024

Correction... [...iterable] is in ES6... I got confused there for a while (I was thinking of array comprehensions).

from traceur-compiler.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.