Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES2024: array-grouping #1716

Open
2 tasks
Tracked by #1706
azu opened this issue Feb 10, 2024 · 3 comments
Open
2 tasks
Tracked by #1706

ES2024: array-grouping #1716

azu opened this issue Feb 10, 2024 · 3 comments

Comments

@azu
Copy link
Collaborator

azu commented Feb 10, 2024

tc39/proposal-array-grouping: A proposal to make grouping of array items easier

Web互換性のためにObject.groupByになった。
Map.groupBy(array, fn)もある。

グループ化は頻出ではあるので含めるのは妥当そうだけど、配置が難しい

  • Array.prototype.groupObject.groupBy(array, cb)
  • Array.prototype.groupToMapMap.groupBy(array, cb)

という経緯。
どちらも配列を引数として受け取るようになってるので、配列関係。

データの変換的に見れば

  • Object.groupBy は 配列をオブジェクトにするメソッド
  • Map.groupBy は配列をMapにするメソッド

として捉えられる。

Object.groupByは、 配列 to objectなので、Array.prototype.reduce の近くにあるのが良さそう。
Map.groupByは、Map/Setにあるのが良さそう。
Map.groupByはちょっと必要かは怪しい。

TODO

  • Object.groupBy: 配列の章に追加する
  • Map.groupBy は Map/Setの章に追加する?

Originally posted by @azu in #1706 (comment)

@azu azu changed the title proposal-array-grouping ES2024: array-grouping Feb 10, 2024
@azu azu mentioned this issue Feb 10, 2024
14 tasks
@azu azu added this to the v6(ES2024) milestone Feb 10, 2024
@azu
Copy link
Collaborator Author

azu commented Mar 22, 2024

@koralle 配列の章とMap/Setの章は別々のPRとして進めるのが良いと思います。(Assignするためにmentionしちゃいましたが、なぜかAssignはできなかった…)

@azu
Copy link
Collaborator Author

azu commented Mar 22, 2024

  • ユースケース/モチベーションの整理
  • 他の書籍やサイトなどでの紹介例を集める(MDNとかEloquent JavaScriptとかhttps://javascript.info/ とかブログとか)
  • ユースケースの章でgroupByを使うべき場所がないかを確認する
  • わかりやすくシンプルなExampleを考える
  • 文章として追加する

作業としては毎回こういうイメージのことをやっています。

ちょっと考えるところとしては、Web互換性のためにStatic Methodになってるというのを説明するべきかどうかという点ぐらいなのかなとは思います。(多分冗長になるので不要になりそうな気はしています)

参考

@koralle
Copy link

koralle commented Apr 1, 2024

@azu
ありがとうございます。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants