The following test fails:
final map = CombinedMapView([{'1': 1, '2': 2, '3': 3}, {'2': 22, '4': 44}]);
expect(map.length, equals(4));
expect(map.keys.toList(), equals(['1', '2', '3', '4']));
The first expectation fails because length returns 5.
The second, because keys returns ['1', '2', '3', '2', '4'].
This seems to violate Map's interface, which says:
There is a finite number of keys in the map, and each key has exactly one value associated with it.
This was a problem for me because I needed something that looks just like a normal Map but based on two other Maps, and which lets a map coming first "override" values on the map coming later in the list of maps. I believe that's the main purpose of combining maps (possibly unmodifiable), but due to this issue, it can't be used like that.
The following test fails:
The first expectation fails because
lengthreturns5.The second, because
keysreturns['1', '2', '3', '2', '4'].This seems to violate
Map's interface, which says:This was a problem for me because I needed something that looks just like a normal
Mapbut based on two other Maps, and which lets a map coming first "override" values on the map coming later in the list of maps. I believe that's the main purpose of combining maps (possibly unmodifiable), but due to this issue, it can't be used like that.