+1

A range function would be a great (possibly better) alternative, especially if 
combined with array comprehensions:

     let filled = [ myValue for _ of Array.range(1,3) ]

But we are getting into standard library territory again (after ES6 the only 
remaining Python advantage, IMO). There is remarkably little competition in 
this space. I’m wondering at what point Underscore.js can be considered proven 
enough to add its functionality to the language proper. Or is there something 
else that can be done to figure out what’s still missing from the standard 
library? Then we still need a more comprehensive collection library.

On Dec 12, 2012, at 17:20 , Herby Vojčík <he...@mailbox.sk> wrote:

> 
> 
> Rick Waldron wrote:
>> 
>> 
>> 
>> On Wed, Dec 12, 2012 at 1:59 AM, Axel Rauschmayer <a...@rauschma.de
>> <mailto:a...@rauschma.de>> wrote:
>> 
>>    I would still love to have something like that in ES6 (loosely
>>    similar to String.prototype.repeat). Once you have that, you can
>>    e.g. use Array.prototype.map to do more things.
>> 
>>    Two possibilities:
>>    - Array.repeat(undefined, 3) -> [ undefined, undefined, undefined ]
>>    - [ undefined ].repeat(3) -> [ undefined, undefined, undefined ]
>> 
>> 
>> Array Comprehensions!
>> 
>> This is probably wrong, so treat it more like an idea and less like a
>> matter of fact:
>> 
>> [ undefined for x of new Array(3) ].map( v => ... );
>> 
>> [ undefined for x of [0,0,0] ].map( v => ... );
> 
> Well, for the few occasions I did something in Python, I did it this way, but 
> with range(3) in place of new Array(3).
> 
> If it's not a sin to do it this way, then please allow it by adding range 
> (however called) in ES6.
> 
>> Rick
> 
> Herby
> 
> P.S.: Or allow it some different way, it depends. integers().limit(3) is 
> fine, too; if having infinite generator of increasing integers and decorator 
> stopping after n items is better way.
> 
> P.P.S.: This open lots of ways. It can as well be 
> [...infiniteStreamOf(undefined).limit(3)] (lotsOf(...) is shorter).
> 
> P.P.P.S.: That said, `looping(a,b,c)` generating a,b,c in a neverending loop 
> (for any number of parameters) would be a good building block.
> 

-- 
Dr. Axel Rauschmayer
a...@rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to