merge method

Bundle merge(
  1. Bundle other
)

Makes new Bundle which merged this with other. Last modified time will update as now. Items that not in this but other are append. Rest of all are same as this.

Implementation

Bundle merge(Bundle other) {
  final keys = items.map((item) => item.name).toSet();
  final otherKeys = other.items.map((item) => item.name).toSet();
  final newKeys = otherKeys.difference(keys);
  final newItems =
      other.items.where((item) => newKeys.contains(item.name)).toSet();

  return Bundle(
    lastModified: DateTime.now(),
    author: author,
    context: context,
    locale: locale,
    items: items.union(newItems),
  );
}