takeIf method

List<T> takeIf(
  1. bool f(
    1. T
    )
)

Take if f is true. Returns a new list with the elements taken if f is true.

Implementation

List<T> takeIf(bool Function(T) f) {
  final list = <T>[];
  for (final item in this) {
    if (f(item)) {
      list.add(item);
    }
  }
  return list;
}