mc_gallery/lib/features/core/data/extensions/map_extensions.dart

18 lines
566 B
Dart
Raw Normal View History

2022-12-25 00:55:53 +00:00
import 'dart:collection';
2022-12-19 13:03:38 +00:00
extension MapExtensions<A, B> on Map<A, B> {
Map<A, B> get deepCopy => {...this};
/// Returns the values of a [Map] at given [keys] indices.
Iterable<B> valuesByKeys({required Iterable<A> keys}) => keys.map((final key) => this[key]!);
2022-12-19 13:03:38 +00:00
}
2022-12-25 00:55:53 +00:00
extension LinkedHashMapExtensions<A, B> on LinkedHashMap<A, B> {
/// Updated the value at [valueIndex] to [newValue], in addition to preserving the order.
void updateValueAt({
required int valueIndex,
required B newValue,
}) =>
this[keys.toList()[valueIndex]] = newValue;
}