sortWithAsyncKey<K extends Comparable<Object> > method
A version of sortWithKey that allows the sort key to be computed asynchronously.
Implementation
Future<void> sortWithAsyncKey<K extends Comparable<Object>>(
Future<K> Function(E) key,
) async {
var keys = await Future.wait([for (var element in this) key(element)]);
assert(length == keys.length);
final keyValues = [
for (var i = 0; i < length; i += 1) MapEntry(keys[i], this[i]),
]..sort(_compareKeys);
// Copy back to mutate the original [List].
for (var i = 0; i < length; i += 1) {
this[i] = keyValues[i].value;
}
}