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

JVM / Python / OOP like group_by view #1815

Open
haleyk10198 opened this issue Apr 8, 2024 · 0 comments
Open

JVM / Python / OOP like group_by view #1815

haleyk10198 opened this issue Apr 8, 2024 · 0 comments

Comments

@haleyk10198
Copy link

haleyk10198 commented Apr 8, 2024

Hi,

I am writing to propose a view that mimics the behavior of group_by in other major OOP languages, docs: Kotlin, Scala, Python/Panda .

Schematically, the view is expected to have a signature of
auto group_by(ranges::viewable_range R&& r, Pred&& pred)

where,
return type should be an iterable of key-value tuples, where each value is also an iterable of ranges::range_value_t<R>
Pred produces a key value (instead of boolean value)

The closest adaptor I know using STL is (omitting forward semantics for brevity),
std::views::transform([](auto&& ele) { return std::tuple { Pred(ele), ele }; } | std::ranges::to<std::unordered_multimap>() | std::views::chunk_by(auto&& lhs, auto &&rhs) { std::get<0>(lhs) == std::get<0>(rhs); }

Though return type is a bit different it suffices for the use case: group by key, then do action on similar elements.

I am aware that chunk_by was previously named as group_by by FP conventions, and the name collision may be confusing.

As this adaptor is rather common in other OOP languages' standard library implementations, I would like to first check if this has been previously discussed in this repo.

Much thanks, for your attention, and your continued contribution to this repo. :)

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

No branches or pull requests

1 participant