Git Product home page Git Product logo

Comments (11)

jridgewell avatar jridgewell commented on August 17, 2024 3

I think having the name groupBy is important for recognizability (our own ecosystem precedent and from other languages). I don't think there's a clear pattern for naming factory methods.

from proposal-array-grouping.

ljharb avatar ljharb commented on August 17, 2024 2

“fromX” means it’s an X already, and as you said, it’s ungrouped.

from proposal-array-grouping.

ljharb avatar ljharb commented on August 17, 2024 2

TC39 reaffirmed consensus today on the existing groupBy name.

from proposal-array-grouping.

acutmore avatar acutmore commented on August 17, 2024 1

The recognisability of the name does sound very valuable. So like {_,Lodash,Ramda}.groupBy, in this situation the namespace should be seen as a general collection of utilities. And having Array.groupBy doesn't scale as nicely to having various different collection types.

from proposal-array-grouping.

bakkot avatar bakkot commented on August 17, 2024 1

@nickmccurdy This method is the opposite of that - your data is not grouped yet, and you want it to be.

from proposal-array-grouping.

ljharb avatar ljharb commented on August 17, 2024 1

Functions are verbs, so that function could be a "grouper" but wouldn't be "groups", a noun - and fromGrouper sounds like it's a fish :-)

from proposal-array-grouping.

ljharb avatar ljharb commented on August 17, 2024

There’s no clear precedent for this - Promise.all and friends produce a Promise, Object.fromEntries and Object.create produce an Object, Array.from produces an Array.

However, Object.keys/values/entries/getOwnPropertyDesceiptor etc operate on an Object.

from proposal-array-grouping.

nickmccurdy avatar nickmccurdy commented on August 17, 2024

How about fromGroups? It aligns with existing static methods like Array.fromAsync.

from proposal-array-grouping.

nickmccurdy avatar nickmccurdy commented on August 17, 2024

I was thinking of it more from the mathematical perspective, where the callback is a functor mapping an ungrouped collection to a grouped collection. Though if the result is too arbitrary, maybe fromGrouping would be more clear.

from proposal-array-grouping.

Zachiah avatar Zachiah commented on August 17, 2024

@nickmccurdy correct me if I'm wrong, but @ljharb I think what @nickmccurdy is suggesting is that groups is referring to the function that converts from "ungrouped" to "grouped". An expansion of the name could be: getGroupsFromGroups and when you consider the "more clear" version he provided: fromGrouping, this makes even more sense: getGroupsFromGrouping.

from proposal-array-grouping.

nickmccurdy avatar nickmccurdy commented on August 17, 2024

I try to avoid putting get in function names as it's usually already obvious. Maybe just groups or grouped could work? Though I'm not sure if they'd have naming collisions.

from proposal-array-grouping.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.