blob: bb767ed99173eebc1015e332ad1f6dee70545912 [file] [log] [blame] [edit]
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
extension MapSorting<K extends Comparable<K>, V extends Object> on Map<K, V> {
Map<K, V> sortOnKey() {
final result = <K, V>{};
final keysSorted = keys.toList()..sort();
for (final key in keysSorted) {
final value = this[key]!;
result[key] = value;
}
return result;
}
}