The type of the input items.
The type of the sort key (must be comparable).
The collection to sort.
An async function that computes the sort key for each element.
Optionaloptions: SortByOptions<I>Configuration options, including concurrency limit.
A cancellable handle that resolves to the sorted array.
const users = [
{ name: 'Alice', age: 30 },
{ name: 'Bob', age: 25 },
{ name: 'Charlie', age: 35 }
];
const handle = sortBy(
users,
async (user, token) => {
await token.sleep(10);
return user.age;
},
);
const result = await handle;
// [{ name: 'Bob', age: 25 }, { name: 'Alice', age: 30 }, { name: 'Charlie', age: 35 }]
Sorts a collection by computing a sort key for each element using an async function. Elements are sorted in ascending order based on their computed keys.
The type of the input items.
The type of the sort key (must be comparable).
The collection to sort.
An async function that computes the sort key for each element.
Optionaloptions: SortByOptions<I>Configuration options, including concurrency limit.
A cancellable handle that resolves to the sorted array.
const users = [
{ name: 'Alice', age: 30 },
{ name: 'Bob', age: 25 },
{ name: 'Charlie', age: 35 }
];
const handle = sortBy(
users,
async (user, token) => {
await token.sleep(10);
return user.age;
},
);
const result = await handle;
// [{ name: 'Bob', age: 25 }, { name: 'Alice', age: 30 }, { name: 'Charlie', age: 35 }]
Sorts a collection by computing a sort key for each element using an async function. Elements are sorted in ascending order based on their computed keys.