This commit is contained in:
2025-03-03 16:15:12 +02:00
parent 24cd167754
commit b780647445
3 changed files with 20 additions and 16 deletions

View File

@@ -1,15 +1,19 @@
Map<T, B> mergeAllMaps<T, B>(List<Map<T, B>> maps, {Function(T key, B value1, B value2)? repeatingKeysValueComparer}) {
Map<T, B> r = <T,B>{};
//
for (Map<T, B> m in maps) {
m.forEach((T key,B value) {
if (!r.containsKey(key)) {
r.addEntries(<MapEntry<T, B>>[MapEntry<T,B>(key, value)]);
} else {
repeatingKeysValueComparer?.call(key, r[key] as B, value);
}
});
extension MapExtensions<B, T> on Map<B, T> {}
extension MapListExtensions<T, B> on List<Map<T, B>> {
Map<T, B> mergeAllMaps({Function(T key, B value1, B value2)? repeatingKeysValueComparer}) {
Map<T, B> r = <T, B>{};
//
for (Map<T, B> m in this) {
m.forEach((T key, B value) {
if (!r.containsKey(key)) {
r.addEntries(<MapEntry<T, B>>[MapEntry<T, B>(key, value)]);
} else {
repeatingKeysValueComparer?.call(key, r[key] as B, value);
}
});
}
//
return r;
}
//
return r;
}
}