serokell / universum

:milky_way: Prelude written in @Serokell
MIT License
174 stars 26 forks source link

[#250] Reexport `group`-like functions from `Data.List.NonEmpty` #260

Closed DK318 closed 2 years ago

DK318 commented 2 years ago

Description

Problem

At this moment group function returns [[a]] instead of [NonEmpty a]. Often returning list of lists is unsafe.

Solution

Replace group export from Data.List with group, groupBy, groupWith and groupAllWith from Data.List.NonEmpty.

Related issues(s)

✓ Checklist for your Pull Request

Ideally a PR has all of the checkmarks set.

If something in this list is irrelevant to your PR, you should still set this checkmark indicating that you are sure it is dealt with (be that by irrelevance).

Related changes (conditional)

Stylistic guide (mandatory)

gromakovsky commented 2 years ago

Btw, there are 2 more functions in Data.List.NonEmpty I would consider exporting:

From my experience, the former might be even more useful than groupBy. You often need to compare by some field and doing groupWith field is more convenient than groupBy (\a b -> field a < field b). The latter is great because it sorts elements. There were a number of times when I made a bug because I (wrongly) expected grouping of all items by group function. Before I discovered groupAllWith, I had to do sorting myself a few times.