deepSearchByKey method

Map deepSearchByKey(
  1. bool predicate(
    1. Object? key
    )
)

Returns new instance of recursively filtered (by key) Map. Does not work with keys as List and Set yet.

Implementation

Map deepSearchByKey(bool predicate(Object? key)) =>
    LinkedHashMap.fromIterable(keys,
        key: (k) => k,
        value: (k) {
          if (this[k] is Map) {
            return (this[k] as Map).deepSearchByKey(predicate);
          } else if (predicate(k)) {
            return this[k];
          }
        })
      ..removeWhere(
          (key, value) => value == null || (value is Map && value.isEmpty));