Fwd: Array additions

2018-03-25 Thread Isiah Meadows
I have a few (typed) array additions I'd like to see added, detailed in this repo. By any chance, how many of these do you all see worth adding, if any? https://github.com/isiahmeadows/array-additions-proposal/ - Isiah Meadows m...@isiahmeadows.com Looking for web consulting? Or a new websi

Re: Proposal: if variable initialization

2018-03-25 Thread Isiah Meadows
Maybe this analogue to the `for (const ... of ...)`: ```js function keyList(map) { const list = new Array(map.size) const iter = map.keys() while (const {done, value} = iter.next(); !done) { list.push(value) } return list } ``` But in general, the more I've thought a

Re: Proposal: if variable initialization

2018-03-25 Thread Naveen Chawla
I don't get it. Please give an example of the per-iteration initialization in the while loop... (the for-loop version before `;` does it before iteration, not per-iteration) On Mon, 26 Mar 2018 at 07:20 Isiah Meadows wrote: > As a counterpoint, Rust and Swift are the opposite: it's only defined

Re: Re: Add "???" Unimplemented

2018-03-25 Thread Isiah Meadows
Even in TypeScript, `never` (the type of functions that never return - throwing ≠ returning) is the subtype of *all* types, even primitives. - Isiah Meadows m...@isiahmeadows.com Looking for web consulting? Or a new website? Send me an email and we can get started. www.isiahmeadows.com On S

Re: Array.prototype.repeat

2018-03-25 Thread Isiah Meadows
Edits: 1. s/Haskell/Swift/g 2. Most of my utility has been in things like random data. Now that I take a second look at this, maybe it's better as just a utility function, not in the standard. (There isn't really anything this could provide that aren't possible otherwise, and it's not as broad of

Re: partial spread syntax

2018-03-25 Thread Tab Atkins Jr.
On Sun, Mar 25, 2018 at 6:20 PM, 月の影 <19511...@qq.com> wrote: > Sometimes I got a infinity iterable sequences, I may want a partial spreed > syntax. `...iterableObject{from, to}` > > For example: > > ```js > function *fibonacci() { > let a = 0, b = 1 > while(1) { > [a, b] = [b, a +

Re: Array.prototype.repeat

2018-03-25 Thread Isiah Meadows
Edit: that `while (i < count)` should be `while (i < end)`, where `end = length * count`. My bad. - Isiah Meadows m...@isiahmeadows.com Looking for web consulting? Or a new website? Send me an email and we can get started. www.isiahmeadows.com On Sun, Mar 25, 2018 at 10:21 PM, Isiah Meadows

Re: Array.prototype.repeat

2018-03-25 Thread Isiah Meadows
That *could* repeat an array, but it's not very good as a polyfill (it creates too many intermediate arrays). I'd expect a polyfill would be closer to this: ```js const ToInteger = x => (x = +x; x - x % 1) Array.prototype.repeat = function repeat(count) { count = ToInteger(count) let o =

Re: Array.prototype.repeat

2018-03-25 Thread Isiah Meadows
I like this idea, and it has plenty of precedent in other languages (Python, Haskell, Clojure, etc.). It's more useful for arrays in my experience than even for strings. - Isiah Meadows m...@isiahmeadows.com Looking for web consulting? Or a new website? Send me an email and we can get started

Re: Proposal: if variable initialization

2018-03-25 Thread Isiah Meadows
As a counterpoint, Rust and Swift are the opposite: it's only defined in the consequent branch, not the alternate. So it could go both ways. But if a value is useful in both branches, I'd prefer to just define the variable in a separate statement, to clarify that it's useful in both branches (expl

Re: Proposal: if variable initialization

2018-03-25 Thread Isiah Meadows
Per-iteration scoping would work just as it does with `for (const foo of bar) { ... }` now, and if it were to make it in (I'm mildly against the feature, BTW), I'd prefer it to be per-iteration like that. - Isiah Meadows m...@isiahmeadows.com Looking for web consulting? Or a new website? Send

partial spread syntax

2018-03-25 Thread ??????
Sometimes I got a infinity iterable sequences, I may want a partial spreed syntax. `...iterableObject{from, to}` For example: ```js function *fibonacci() { let a = 0, b = 1 while(1) { [a, b] = [b, a + b] yield a } } console.log([...fibonacci(){3, 5}]) // [3, 5, 8]

Re: Re: Add "???" Unimplemented

2018-03-25 Thread dante federici
Not a bad idea -- I agree that it really belongs here, but its value is much higher in something like TypeScript, where you can keep the typing signature but have a missing implementation. On Sat, Mar 24, 2018 at 3:32 AM Isiah Meadows wrote: > I would suggest, if you have support in your editor,

Re: Array.prototype.repeat

2018-03-25 Thread J Decker
On Sun, Mar 25, 2018 at 1:40 PM, Claude Pache wrote: > > > Le 25 mars 2018 à 20:27, Cyril Auburtin a > écrit : > > String and Array share a few methods. > > I think `repeat` could exist for Array as well > > At the moment are other more verbose ways to do so: > > - `Array.from({length: n}, () =>

Re: Array.prototype.repeat

2018-03-25 Thread Claude Pache
> Le 25 mars 2018 à 20:27, Cyril Auburtin a écrit : > > String and Array share a few methods. > > I think `repeat` could exist for Array as well > > At the moment are other more verbose ways to do so: > > - `Array.from({length: n}, () => 'foo')` > - `Array(n).fill('foo')` > - `[].concat(...A

Re: Array.prototype.repeat

2018-03-25 Thread Peter Jaszkowiak
I'm guessing this would be an appropriate polyfill: ``` Array.prototype.repeat = function repeat(count) { let output = this; while (--count) { output = output.concat(this); } return output; }; ``` On Sun, Mar 25, 2018 at 12:27 PM, Cyril Auburtin wrote: > String and Array share a few

Array.prototype.repeat

2018-03-25 Thread Cyril Auburtin
String and Array share a few methods. I think `repeat` could exist for Array as well At the moment are other more verbose ways to do so: - `Array.from({length: n}, () => 'foo')` - `Array(n).fill('foo')` - `[].concat(...Array.from({length: 3}, () => ['x', 'y']))` - `[].concat(...Array(3).fill(['x

Re: Proposal: if variable initialization

2018-03-25 Thread Naveen Chawla
Obviously scoped, agreed, but again how would you allow scoped initialization upon each iteration, or is it your preference not to allow that? (again, initializers-as-expressions allows that, despite the other concerns). On Sun, 25 Mar 2018 at 10:57 Isiah Meadows wrote: > 1. My concern with `whi