whereOnly method

List<T> whereOnly(
  1. List<String> keys
)

Gets only those values which is given

Example:

list.whereOnly([key1, key2])

Implementation

List<T> whereOnly(List<String> keys) {
  if (isEmpty) {
    return <T>[];
  }
  final List<T> result = <T>[];
  for (final T element in this) {
    if (element is Map<String, T>) {
      final Map<String, T> map = <String, T>{};
      for (final String key in keys) {
        if (element.containsKey(key)) {
          map[key] = element[key] as T;
        }
      }
      if (map.isNotEmpty) {
        result.add(map as T);
      }
    }
  }
  return result;
}