Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #41417 > unrolled thread
| Started by | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| First post | 2023-08-21 11:42 -0700 |
| Last post | 2023-09-04 06:45 -0700 |
| Articles | 8 — 5 participants |
Back to article view | Back to comp.lang.javascript
JavaScript now supports 'groupBy` "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2023-08-21 11:42 -0700
Re: JavaScript now supports 'groupBy` Julio Di Egidio <julio@diegidio.name> - 2023-09-02 02:50 -0700
Re: JavaScript now supports 'groupBy` luserdroog <luser.droog@gmail.com> - 2023-09-03 06:10 -0700
Re: JavaScript now supports 'groupBy` "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2023-09-03 07:55 -0700
Re: JavaScript now supports 'groupBy` Julio Di Egidio <julio@diegidio.name> - 2023-09-03 08:18 -0700
Re: JavaScript now supports 'groupBy` Mild Shock <janburse@fastmail.fm> - 2023-09-04 01:43 +0200
Re: JavaScript now supports 'groupBy` Arno Welzel <usenet@arnowelzel.de> - 2023-09-03 17:39 +0200
Re: JavaScript now supports 'groupBy` "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2023-09-04 06:45 -0700
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2023-08-21 11:42 -0700 |
| Subject | JavaScript now supports 'groupBy` |
| Message-ID | <b5e3bf33-1b38-4bb1-b6f2-4fdb3348b2afn@googlegroups.com> |
In case you missed it, JavaScript finally implemented a groupBy static method for Object and Map:
Map.groupBy(iterable, callbackFn)
Object.groupBy(iterable, callbackFn)
Example usage from MDN:
const inventory = [
{ name: "asparagus", type: "vegetables", quantity: 9 },
{ name: "bananas", type: "fruit", quantity: 5 },
{ name: "goat", type: "meat", quantity: 23 },
{ name: "cherries", type: "fruit", quantity: 12 },
{ name: "fish", type: "meat", quantity: 22 },
];
...
const restock = { restock: true };
const sufficient = { restock: false };
const result = Map.groupBy(inventory, ({ quantity }) =>
quantity < 6 ? restock : sufficient,
);
console.log(result.get(restock));
// [{ name: "bananas", type: "fruit", quantity: 5 }]
...
const result = Object.groupBy(inventory, ({ type }) => type);
/* Result is:
{
vegetables: [
{ name: 'asparagus', type: 'vegetables', quantity: 5 },
],
fruit: [
{ name: "bananas", type: "fruit", quantity: 0 },
{ name: "cherries", type: "fruit", quantity: 5 }
],
meat: [
{ name: "goat", type: "meat", quantity: 23 },
{ name: "fish", type: "meat", quantity: 22 }
]
}
*/
More info:
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/groupBy>
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/groupBy>
Browser Availability:
<https://caniuse.com/?search=groupby>
If you're using the Babel compiler, here is the core-js setting:
<https://github.com/zloirock/core-js#array-grouping>
[toc] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2023-09-02 02:50 -0700 |
| Message-ID | <7bc9bbab-16dd-40e9-ba65-9377c0ea2fc3n@googlegroups.com> |
| In reply to | #41417 |
On Monday, 21 August 2023 at 20:42:18 UTC+2, Michael Haufe (TNO) wrote: > In case you missed it, JavaScript finally implemented > a groupBy static method for Object and Map You might have missed that it's neither decently supported, nor, as for the enthusiasm, it has anything to do with the aggregation operator by the same name, in fact, with any aggregation at all: this "groupBy" is more of a "partitionBy" and can be implemented in one line of code with an array reduce over the input's keys. Indeed, I'd call it plain clutter. Julio
[toc] | [prev] | [next] | [standalone]
| From | luserdroog <luser.droog@gmail.com> |
|---|---|
| Date | 2023-09-03 06:10 -0700 |
| Message-ID | <00de57e1-5d62-4317-aa14-ce299183e497n@googlegroups.com> |
| In reply to | #41421 |
On Saturday, September 2, 2023 at 4:50:21 AM UTC-5, Julio Di Egidio wrote: > On Monday, 21 August 2023 at 20:42:18 UTC+2, Michael Haufe (TNO) wrote: > > > In case you missed it, JavaScript finally implemented > > a groupBy static method for Object and Map > You might have missed that it's neither decently supported, > nor, as for the enthusiasm, it has anything to do with the > aggregation operator by the same name, in fact, with any > aggregation at all: this "groupBy" is more of a "partitionBy" > and can be implemented in one line of code with an array > reduce over the input's keys. Indeed, I'd call it plain clutter. > > Julio [sad trombone warbling descending glissando w/plunger mute]
[toc] | [prev] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2023-09-03 07:55 -0700 |
| Message-ID | <c4cea9f8-7f3a-44e5-a238-4e43ad2ae929n@googlegroups.com> |
| In reply to | #41421 |
On Saturday, September 2, 2023 at 4:50:21 AM UTC-5, Julio Di Egidio wrote: > On Monday, 21 August 2023 at 20:42:18 UTC+2, Michael Haufe (TNO) wrote: > > > In case you missed it, JavaScript finally implemented > > a groupBy static method for Object and Map > You might have missed that it's neither decently supported, In case you missed it, I provided availability statistics in my post plus the babel plugin. > nor, as for the enthusiasm, it has anything to do with the > aggregation operator by the same name, in fact, with any > aggregation at all: this "groupBy" is more of a "partitionBy" > and can be implemented in one line of code with an array > reduce over the input's keys. Indeed, I'd call it plain clutter. Given the Universality and Expressiveness of Fold [1], we can say that about most functions/methods [1] <https://www.cs.nott.ac.uk/~pszgmh/fold.pdf>
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2023-09-03 08:18 -0700 |
| Message-ID | <8577d73e-85fa-4082-b053-09773c20d9a0n@googlegroups.com> |
| In reply to | #41423 |
On Sunday, 3 September 2023 at 16:56:01 UTC+2, Michael Haufe (TNO) wrote: > On Saturday, September 2, 2023 at 4:50:21 AM UTC-5, Julio Di Egidio wrote: > > On Monday, 21 August 2023 at 20:42:18 UTC+2, Michael Haufe (TNO) wrote: > > > > > In case you missed it, JavaScript finally implemented > > > a groupBy static method for Object and Map > > > > You might have missed that it's neither decently supported, > > In case you missed it, I provided availability statistics in my > post plus the babel plugin. You provided statistics that apparently you can't read. > > nor, as for the enthusiasm, it has anything to do with the > > aggregation operator by the same name, in fact, with any > > aggregation at all: this "groupBy" is more of a "partitionBy" > > and can be implemented in one line of code with an array > > reduce over the input's keys. Indeed, I'd call it plain clutter. > > Given the Universality and Expressiveness of Fold [1], we can > say that about most functions/methods No, we can't say what I have said of most functions/methods, but again, you can't even read, apparently. EOD. Julio
[toc] | [prev] | [next] | [standalone]
| From | Mild Shock <janburse@fastmail.fm> |
|---|---|
| Date | 2023-09-04 01:43 +0200 |
| Message-ID | <ud35na$kfeq$1@solani.org> |
| In reply to | #41421 |
Omg, the little italian was at it again. How cringe... What is he, a Bolchevik that is about to kill the Romanov Family? Julio Di Egidio schrieb: > On Monday, 21 August 2023 at 20:42:18 UTC+2, Michael Haufe (TNO) wrote: > >> In case you missed it, JavaScript finally implemented >> a groupBy static method for Object and Map > > You might have missed that it's neither decently supported, > nor, as for the enthusiasm, it has anything to do with the > aggregation operator by the same name, in fact, with any > aggregation at all: this "groupBy" is more of a "partitionBy" > and can be implemented in one line of code with an array > reduce over the input's keys. Indeed, I'd call it plain clutter. > > Julio >
[toc] | [prev] | [next] | [standalone]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2023-09-03 17:39 +0200 |
| Message-ID | <kljnl6Fnhk0U1@mid.individual.net> |
| In reply to | #41417 |
Michael Haufe (TNO), 2023-08-21 20:42: > In case you missed it, JavaScript finally implemented a groupBy static method for Object and Map: > > Map.groupBy(iterable, callbackFn) > Object.groupBy(iterable, callbackFn) Which is not widely supported yet: <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/groupBy#browser_compatibility> -- Arno Welzel https://arnowelzel.de
[toc] | [prev] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2023-09-04 06:45 -0700 |
| Message-ID | <7ebebcfc-25ba-40d6-ad00-09cdc03e1543n@googlegroups.com> |
| In reply to | #41425 |
On Sunday, September 3, 2023 at 10:39:28 AM UTC-5, Arno Welzel wrote: > Michael Haufe (TNO), 2023-08-21 20:42: > > In case you missed it, JavaScript finally implemented a groupBy static method for Object and Map: > > > > Map.groupBy(iterable, callbackFn) > > Object.groupBy(iterable, callbackFn) > Which is not widely supported yet: > > <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/groupBy#browser_compatibility> > Which I shared already in my OP: <https://caniuse.com/?search=groupby> Hence my reference to the polyfill: <https://github.com/zloirock/core-js#array-grouping>
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web