elm-community / list-extra

Convenience functions for working with List.
http://package.elm-lang.org/packages/elm-community/list-extra/latest
MIT License
135 stars 59 forks source link

remove Set usage in unique functions, drop comparable restriction #151

Closed cjoach closed 3 years ago

cjoach commented 3 years ago

The comparable type variable is restrictive in the form that it doesn't work with custom types. For the family of unique functions, only the == operator is needed so comparable is not strictly needed. The restriction seemed to come from using Set to containing unique elements instead of a list.

I removed the restriction, please tell me if I'm overlooking something.

Chadtech commented 3 years ago

Awesome discovery. It seems plausible that this was made this way for a good reason, tho I dont know what that reason is.

I made this benchmark (https://ellie-app.com/f5Kzb3J2cx9a1) and it seems that the List implementation is faster for about 100 element long lists, and at around 150 it becomes slower. Quite a lot depends on the composition of the list, and the function used to determine uniqueness.

Seems like a good trade off. I am not sure. I'll think about it and come back to this later.

Chadtech commented 3 years ago

Alright. Lets do it. 40% Better performance on the range of 0-100 sized Lists and being able to get uniqueness on any kind of element is worth the 30% drop in performance on >200 sized Lists.

Chadtech commented 3 years ago

Thanks @cjoach