Closed chshersh closed 6 years ago
My personal intuition is that such functions shouldn't be in prelude, maybe in serokell-util
.
serokell-util
probably shouldn't exist. So I don't want to add more functions to it.
What about renaming them a bit?
Your groupListBy
looks more essential and is more similar to the true group
than your current groupBy
.
Also, grouping which returns HashMap b a
implicitly throws duplicating elements away, and I think that would be better stated explicitly via NE.head <$> groupListBy f l
or by renaming to some groupByOne
It's a good advice to name HashMap b [a]
function as groupBy
. But then we need to think how to name HashMap b a
. Maybe groupSingleBy
or groupOneBy
or nubBy
or hashifyBy
or something else.
Btw, NE.head <$> groupListBy f l
is very inefficient implementation.
Btw, NE.head <$> groupListBy f l is very inefficient implementation.
Why very?
@Martoon-00 Well, not exactly very. It's really hard to say anything w/o benchmarks. But implementing groupBy :: ... HashMap b [a]
is only possible using (++)
operator. This results in extra step for each value.
It seems to me that similar efficiency leaks are all over our code and no one concerns, but ok, perhaps library have to suggest performant stuff if it can. I believe that you'll stop on so cool name for that function that it will be much more pleasant to use than ... groupBy
when the option is given :wink:
Currently we don't have agreement which container to use: HashMap
or just Map
. So I postpone this issue to better time...
These functions are nice to have somewhere. They must be fast, so there should be instances for both HashMap
and Map
and maybe list ((b, [a])
). I suggest to have these in separate modules, maybe utility package, maybe in Map
or HashMap
themselves. It's also easy to write the optimal version for yourself if you need to, so I don't think the proposal is useful.
Okay, it's not so common. I think we should start with having these functions in some utilities package and then just see how it's going and how often they used.
I really very often want to have function like this:
These function don't even exist in any packages! I propose to add some reasonable grouping. If you have your ideas how grouping function should be look like, please, share. My version is the following next:
UPDATE: better function signatures adapted to
universum