typelevel / cats

Lightweight, modular, and extensible library for functional programming.
https://typelevel.org/cats/
Other
5.25k stars 1.21k forks source link

Optimize `distinct`/`distinctBy` implementations for non-empty collections #4610

Open satorg opened 4 months ago

satorg commented 4 months ago

A follow up for #4608 (see my comment https://github.com/typelevel/cats/pull/4608#discussion_r1626935568). For an example of a pretty well optimized implementation one could check out the corresponding methods in Chain:

https://github.com/typelevel/cats/blob/930f25c544c787fe6703349090b5210a35249e70/core/src/main/scala/cats/data/Chain.scala#L797-L813 https://github.com/typelevel/cats/blob/930f25c544c787fe6703349090b5210a35249e70/core/src/main/scala/cats/data/Chain.scala#L826-L842
sinpat commented 4 days ago

Hi, I would like to implement this optimization. I haven't contributed yet and I think this could be a good first issue.