traverse static method

({bool exists, dynamic value}) traverse(
  1. Map map,
  2. String key
)

Implementation

static ({bool exists, dynamic value}) traverse(Map map, String key) {
  var subPaths = key.split(".");
  dynamic value = map;
  for (var path in subPaths) {
    if (value is! Map) return (exists: false, value: null);
    if (!value.containsKey(path)) return (exists: false, value: null);
    value = value[path];
  }
  return (exists: true, value: value);
}