• JavaScript now supports 'groupBy`

    From Michael Haufe (TNO)@21:1/5 to All on Mon Aug 21 11:42:13 2023
    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>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Julio Di Egidio@21:1/5 to All on Sat Sep 2 02:50:15 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From luserdroog@21:1/5 to Julio Di Egidio on Sun Sep 3 06:10:05 2023
    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]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Michael Haufe (TNO)@21:1/5 to Julio Di Egidio on Sun Sep 3 07:55:55 2023
    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>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Julio Di Egidio@21:1/5 to All on Sun Sep 3 08:18:55 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Arno Welzel@21:1/5 to All on Sun Sep 3 17:39:19 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mild Shock@21:1/5 to Julio Di Egidio on Mon Sep 4 01:43:39 2023
    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


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Michael Haufe (TNO)@21:1/5 to Arno Welzel on Mon Sep 4 06:45:26 2023
    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>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)