unique<R> method

Iterable<T> unique<R>([
  1. R keyGetter(
    1. T e
    )?
])

Implementation

Iterable<T> unique<R>([R Function(T e)? keyGetter]) {
  Set<dynamic> keys = {};
  dynamic Function(T e) getKey = keyGetter ?? (T e) => e;
  return where((element) {
    var key = getKey(element);
    if (keys.contains(key)) {
      return false;
    } else {
      keys.add(key);
      return true;
    }
  });
}