uniqueEntries<K, V> function

List<MapEntry<K, V>> uniqueEntries<K, V>(
  1. Iterable<MapEntry<K, V>> entries
)

Implementation

List<MapEntry<K, V>> uniqueEntries<K, V>(Iterable<MapEntry<K, V>> entries) {
  final uniqueKeys = <K>{};
  final uniqueValues = <V>{};
  final unique = <MapEntry<K, V>>[];

  for (var entry in entries) {
    if (!uniqueKeys.contains(entry.key) &&
        !uniqueValues.contains(entry.value)) {
      uniqueKeys.add(entry.key);
      uniqueValues.add(entry.value);
      unique.add(MapEntry(entry.key, entry.value));
    }
  }

  return unique;
}