onlyValues<T> static method

List<T> onlyValues<T>(
  1. Iterable<T> list,
  2. Iterable<T> values
)

Returns the elements of list that are also in values.

Arr.onlyValues([1, 2, 3, 4], [2, 4, 9]); // [2, 4]

Implementation

static List<T> onlyValues<T>(Iterable<T> list, Iterable<T> values) {
  final include = values.toSet();
  return [
    for (final v in list)
      if (include.contains(v)) v,
  ];
}