blob: 8948770fb5849b78ba69bd13aa8693ad655ed99b [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) {
result[key] = this[key] as V;
}
return result;
}
}