5 ms·
Congrats on your new role! Currently, I feel like addition to JavaScript is a lot slower than new CSS features, for example. What do you think are the chances t
by selfmodruntime 5y ago
Congrats on your new role! Currently, I feel like addition to JavaScript is a lot slower than new CSS features, for example. What do you think are the chances that JS will one day get a larger batch of STL functions, instead of about a dozen each year?
- lucacasonato 5y agoI hope the pace will accelerate. The real questions is what functions we need though. Some candidates that I would love to see are better helper functions on iterators, and Uint8Array<->base64/hex. Most of the "standard library" in most languages is related to IO, and for JS is dependant on the host (the web, Deno, Node) so not something TC39 will touch directly. Do you have ideas for standard library functions that you think are missing?
- deleted 5y ago[deleted]
- amitport 5y ago'range' a-la python
- wruza 5y agoRange a-la python is a generator and is pretty straightforward in js as is. There is no need for a complicated solution and/or as part of stdlib, imo: function* range(x, y) { while (x <= y) {yield x++} // or ‘<‘ if you want half-open one } for (let n of range(3, 5)){ console.log(n) } array = [...range(3, 5)] console.log(array)
- amitport 5y agoIt's also straight forward to implement in python. It is common enough to be standard so people won't reinvent the wheel. And it should be available to people learning the language before they learn generators. Array.prototype.indexOf is also pretty simple as are many core functions.
- amitport 5y ago'reversed' a-la python
- lucacasonato 5y agoCurrently in stage 2 as `Array.prototype.toReversed`: https://github.com/tc39/proposal-change-array-by-copy https://github.com/tc39/proposal-change-array-by-copy
- amitport 5y agoNice, I didn't know about that, but in any case note that IMO it should be part of the Iterable protocol. Also note that the proposal above creates a copy on reverse AFAIKT.
- amitport 5y ago'zip' a-la python
- lucacasonato 5y agoI have often needed this too. Noted.
- Zababa 5y agoI often miss map, reduce and filter on iterators, though this is already a stage 2 proposal: https://github.com/tc39/proposal-iterator-helpers https://github.com/tc39/proposal-iterator-helpers.
- lucacasonato 5y agoThis is definitely something I am interested in pushing too. Iterators have not gotten the love they deserve.
- Zababa 5y agoThat's great to hear! Congratulations and thank you for your work.
- FragenAntworten 5y ago'enumerate', as in Python. 'clamp' and 'sortBy', as in Lodash. Set methods for union, intersection, difference, etc.
- tempodox 5y agoRe set operators: For completeness' sake there would have to be a way to specify how set elements are to be tested for equality.
- tarjei_huse 5y agoI miss being able to create a hash from an array in a quick way. You always end up with let bar = [{id: zz, }, {id: y},...] let foo = {} bar.forEach(v => foo[v.id] = v) I'd love to have something like: let foo = bar.toMap(v => [v.id, v])
- wiredearp 5y agonew Map([[k1,v1], [k2, v2]]) can do that. Or Object.fromEntries with the same argument.
- tarjei_huse 5y agoThanks! You still need to create the middle datastructure ( [[k1,v1], [k2, v2]] ) but it is an improvement :)
- wiredearp 5y agoAh yes, true, you always need to map the things ID to the thing itself, so that middle data structure is actually quite annoying :)
- keville 5y agoconst foo = bar.reduce((hash, item) => { hash[item.id] = item; return hash; }, {});
- runarberg 5y agolet foo = Object.fromEntries(bar.map((v) => [v.id, v]));
- keville 5y agoIt is not necessary to create any extraneous data structures to do OP's one-liner. This creates n+1 new arrays that must be garbage-collected.
- 5y ago
- wiredearp 5y agoImmutable data structures are on the agenda over in https://github.com/tc39/proposal-record-tuple https://github.com/tc39/proposal-record-tuple and I would vote for that in Deno while I have the chance.
- lucacasonato 5y agoYup, we'll ship them once they go Stage 3/4 (when Chrome ships them in stable).
- aadams 5y agoPlease have someone on your team take a good hard look at the current proposal-pipeline-operator: https://github.com/tc39/proposal-pipeline-operator https://github.com/tc39/proposal-pipeline-operator It started as a Function Composition proposal (using the pipe operator |>) but after a change of leadership it has turned into something much different. We might need another perspective on the current trajectory of this proposal, as in its current form it seems to many in the community it might take JS in the wrong direction. Thanks!
- wruza 5y agoIf you want a feedback, I do not find |> versions much (if at all) easier to read. The noise is as high as in a regular function-based chaining: await chain( Object.keys(envars) .map(envar => `${envar}=${envars[envar]}`) .join(' '), text => `$ ${text}`, text => chalk.dim(text, 'node', args.join(' ')), colored => console.log(colored), ) I don’t want to sound too negative, but this seems like a pointless extension only to bring the burden of support for some syntactic flavor. React example is special though. It feels like very helpful in expr-only context, but in-array ifs and fors would do better there: <ul> {[ for (v of vs) { const text = foo(v) yield <li>{text}</li> }, if (vs.length == 0) { yield <li>No items</li> }, ]}