https://github.com/busterc/merge_map_null_safety
:dart: Dart and/or Flutter - Combine multiple Maps into one (with null safety). Equivalent to Object.assign in JS.
https://github.com/busterc/merge_map_null_safety
Last synced: 6 months ago
JSON representation
:dart: Dart and/or Flutter - Combine multiple Maps into one (with null safety). Equivalent to Object.assign in JS.
- Host: GitHub
- URL: https://github.com/busterc/merge_map_null_safety
- Owner: busterc
- License: mit
- Created: 2022-04-15T20:28:39.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-04-15T20:32:45.000Z (about 4 years ago)
- Last Synced: 2025-02-06T06:34:34.850Z (about 1 year ago)
- Language: Dart
- Size: 2.93 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# merge_map_null_safety
> Combine multiple Maps into one ([with null safety](https://dart.dev/null-safety)). Equivalent to
[Object.assign](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
in JS.
## Example
```dart
import "package:merge_map_null_safety/merge_map.dart";
/// Map mergeMap(Iterable> maps, {bool recursive: true, bool acceptNull: false})
///
/// Merges the values of the given maps together.
///
/// `recursive` is set to `true` by default. If set to `true`,
/// then nested maps will also be merged. Otherwise, nested maps
/// will overwrite others.
///
/// `acceptNull` is set to `false` by default. If set to `false`,
/// then if the value on a map is `null`, it will be ignored, and
/// that `null` will not be copied.
main() {
Map map1 = {'hello': 'world', 'bye': null};
Map map2 = {'foo': {'bar': 'baz', 'this': 'will be overwritten'}};
Map map3 = {'foo': {'john': 'doe', 'this': 'overrides previous maps'}};
Map mergedWithNulls = mergeMap([map1, map2, map3], acceptNull: true);
print(mergedWithNulls);
// {hello: world, bye: null, foo: {bar: baz, john: doe, this: overrides previous maps}}
Map mergedWithoutNulls = mergeMap([{}, map1]);
print(mergedWithoutNulls);
// {hello: world}
}
```