removeDuplicatedBy<T, U> function

Iterable<T> removeDuplicatedBy <T, U>(
  1. Iterable<T> list,
  2. _IterableFunction<T, U> fn
)

Remove duplicated values from an iterable given a predicate without modifying the original iterable.

Implementation

Iterable<T> removeDuplicatedBy<T, U>(
    Iterable<T> list, _IterableFunction<T, U> fn) {
  final values = <U, bool>{};
  return list.where((i) {
    final value = fn(i);
    return values.update(value, (_) => false, ifAbsent: () => true);
  }).toList();
}