filterList<T> function

List<T> filterList<T>(
  1. bool filterFunction(
    1. T sub
    ),
  2. Iterable<T> original
)

Only keep elements that meet criteria

Implementation

List<T> filterList<T>(
    bool Function(T sub) filterFunction, Iterable<T> original) {
  if (original.isEmpty) {
    return [];
  }

  List<T> copy = List.from(original);
  for (T v in listNub(original)) {
    if (!filterFunction(v)) {
      copy.removeWhere((element) => element == v);
    }
  }

  return copy;
}