es-toolkit icon indicating copy to clipboard operation
es-toolkit copied to clipboard

Inconsistent api between sortBy and uniqBy

Open bertyhell opened this issue 1 month ago • 2 comments

I noticed this difference between the sortBy and uniqBy (and maybe other functions) where the sortBy takes an array and either a list op properties or a list of mapper functions But uniqBy only takes a mapper function

Is there a reason for this?

Or could we extend the uniqBy api to:

uniqBy(T[], keyof T | (item: T) => U)

  • items: same as before
  • second argument:
    • either a property name string
    • or a mapper function that returns the value to check for uniqueness

In my code this would quite often make it easier to read since i wouldn't always need a mapper arrow function.

Image

bertyhell avatar Nov 10 '25 15:11 bertyhell