mobily / ts-belt

🔧 Fast, modern, and practical utility library for FP in TypeScript.
https://mobily.github.io/ts-belt
MIT License
1.11k stars 31 forks source link

Feature request: sortByMultiple #45

Open rodrigofariow opened 2 years ago

rodrigofariow commented 2 years ago

Hi there! :)

I was looking for something like lodash's sortBy with multiple accessors, e.g:

sortBy(users, [user => user.name, user => user.age]);

Why? I know this could be implemented using the existing A.sortBy function but after 2 accessors it becomes tedious and prone to error. Lodash implementation might also not be the fastest possible.

Would something like sortByMultiple be on the roadmap for ts-belt?

Api suggestion:

function sortByMultiple<A, B>(xs: Array<A>, sortFns: Array<(_1: A) => B>): Array<A>
function sortByMultiple<A, B>(sortFns: Array<(_1: A) => B>): (xs: Array<A>) => Array<A>

Thank you for your time 🙏

mobily commented 1 year ago

reference: https://github.com/mobily/ts-belt/pull/58