6 ms·
I 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 it
by lucacasonato 5y ago
I 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).