Skip to content

Commit c63dff2

Browse files
committed
Improve compare function in sortedBy extension
1 parent fd91b67 commit c63dff2

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

pkgs/collection/lib/src/iterable_extensions.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ extension IterableExtension<T> on Iterable<T> {
7676
K Function(T element) keyOf, {
7777
bool ascending = true,
7878
}) {
79-
int compare(K a, K b) => ascending ? a.compareTo(b) : b.compareTo(a);
79+
final compare =
80+
ascending ? (K a, K b) => a.compareTo(b) : (K a, K b) => b.compareTo(a);
8081
var elements = [...this];
8182
mergeSortBy<T, K>(elements, keyOf, compare);
8283
return elements;

0 commit comments

Comments
 (0)