5 ms·
Maybe im being naive, but i want more iter methods on nearly all collection primitives. {}.map? someSet.reduce? Ya, sure, some default behavior would need to be
by cdaringe 2y ago
Maybe im being naive, but i want more iter methods on nearly all collection primitives. {}.map? someSet.reduce? Ya, sure, some default behavior would need to be assumed. I wager most practitioners would delight in it.
While we’re here, find_map, filter_map, take, take_while… i want excellent std iter tools. They’re not big or complicated impls, but they sure would have big impact if available out of the box!
- nsonha 2y agoMaybe Deno @std/collections helps, it's now a separare library: https://jsr.io/@std/collections/doc https://jsr.io/@std/collections/doc
- ameliaquining 2y agoMany of these are at stage 3 of the standardization process and have a good chance of shipping soon: https://github.com/tc39/proposal-iterator-helpers https://github.com/tc39/proposal-iterator-helpers (They're not on objects, which I think is probably for the best; every method on Object.prototype is a shadowing risk and so we're unlikely to see any besides the ones that already exist. You can always use Object.entries; if your object has so many dynamically-computed properties that eagerly collecting them is a performance concern, then it should probably be a Map.)
- nobleach 2y agoAgreed. But there's nothing precluding someone from implementing Symbol.iterator on Object: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... Not saying anyone SHOULD do this... just that one _could_.
- derefr 2y ago> if your object has so many dynamically-computed properties that eagerly collecting them is a performance concern, then it should probably be a Map Should be, but there's so much legacy code that is going to hand you objects. Also, unless you go to a weirdly large amount of effort, JSON.parse will give you objects.
- tracker1 2y agoEven then... [Object] could just iterate [k,v] unless the behavior is overridden... even then that's probably appropriate for something like weakmap anyhow.
- cdaringe 2y agoThats a nice set of improvements! Thx for the ref On the proto extension: Sure. Fair argument. Id still be interested in a world where theyre there and non enumerable, or there but behind an .iter() field.