Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new Dart 2 Map methods to BiMap #423

Merged
merged 5 commits into from
Mar 23, 2018
Merged

Add new Dart 2 Map methods to BiMap #423

merged 5 commits into from
Mar 23, 2018

Conversation

srawlins
Copy link
Contributor

@srawlins srawlins commented Mar 9, 2018

No description provided.

_cached = new HashBiMap._from(_inverse, _map);
}
return _cached;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With null-aware assignment:

BiMap<V, K> get inverse => _cached ??= new HashBiMap._from(_inverse, _map);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it. Done.

}
return _cached;
Iterable<MapEntry<K, V>> get entries {
return keys.map((K key) => new MapEntry<K, V>(key, this[key]));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not returning _map.entries ?

Iterable<MapEntry<K, V>> get entries => _map.entries;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

var entry = transform(key, this[key]);
result[entry.key] = entry.value;
}
return result;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not returning _map.map(transform) ?

  Map<K2, V2> map<K2, V2>(MapEntry<K2, V2> transform(K key, V value)) {
    return _map.map(transform);
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* master:
  Add new Dart 2 Iterable and List methods (google#422)
  Document google#373 as breaking change (google#424)
  Add tests of TreeSet removal operations (google#420)
throw new UnimplementedError("addEntries");
void addEntries(Iterable<MapEntry<K, V>> entries) {
for (var entry in entries) {
this[entry.key] = entry.value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implement this using _add since it should apply the same invariants.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

throw new UnimplementedError("map");
}
Map<K2, V2> map<K2, V2>(MapEntry<K2, V2> transform(K key, V value)) =>
_map.map(transform);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Map.map document the expected return type? If it's expected to be a BiMap, we need to apply the invariants from _add (i.e. that not only must the keys be unique, but so must the values, since they're the keys of the inverse).

If it's not, then I think this is fine as-is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't document really.

My thought is it looks just like List.map, Set.map`, ...: you don't expect a List or a Set out the other side; you just expect an Iterable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. That sounds perfectly reasonable to me.

void removeWhere(bool test(K key, V value)) {
throw new UnimplementedError("removeWhere");
_map.removeWhere(test);
_inverse.removeWhere((v, k) => test(k, v));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Let's do this in the same order as remove... not that it really matters :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@srawlins
Copy link
Contributor Author

R rrr rrrrrrready to merge!

@cbracken cbracken merged commit 8ad2873 into google:master Mar 23, 2018
srawlins added a commit to srawlins/quiver-dart that referenced this pull request Mar 23, 2018
* master:
  Add new Dart 2 Map methods to BiMap (google#423)
  Add new Dart 2 Map, Iterable, and List methods to multimap stuff (google#425)
  Add .dart_tool to gitignore (google#431)
  Update changelog for LruMap fix (google#430)
  Ensure that LruMap linkage is preserved (google#429)
  Update CHANGELOG.md (google#428)
  Update CHANGELOG/pubspec to include 0.28.1 (google#427)
@cbracken
Copy link
Member

Partial fix to #418.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants