Consider adding `classify`.

Ignat Insarov kindaro at gmail.com
Mon Aug 24 12:48:44 UTC 2020


Andreas, then how do you feel about adding that one?

    classifyByProjection ∷ Ord π ⇒ (a → π) → [a] → [[a]]
    classifyByProjection f = List.groupBy ((==) `on` f) . List.sortBy
(compare `on` f)

Having thought about it, I have come to agree that it is usually not
hard to define a suitable projection function.

On Mon, 24 Aug 2020 at 12:39, Andreas Abel <andreas.abel at ifi.lmu.de> wrote:
>
> This cannot be done efficiently.  I'd extend the equivalence relation to
> a total order and then use sort and group.
>
> -1 to adding to the standard libraries.  How about publishing this as a
> (well discoverable) package on hackage and see how popular it gets?
>
> On 2020-08-20 19:59, Ignat Insarov wrote:
> > Hello.
> >
> > There has been [a question on Stack Overflow][1] asking for a way to group a
> > list by an equivalence relation. Several answers were proposed over time, and I
> > too [have offered a variant][2]. [I also wrote a benchmark.][3]
> >
> > I propose that the function be added to the standard libraries.
> >
> > [1]: https://stackoverflow.com/q/8262179
> > [2]: https://stackoverflow.com/a/57761458
> > [3]: https://github.com/kindaro/classify-benchmark.git
> > _______________________________________________
> > Libraries mailing list
> > Libraries at haskell.org
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
> >
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries


More information about the Libraries mailing list