getPathValue function

dynamic getPathValue(
  1. List<String> keyPath,
  2. Map<String, dynamic> map
)

Returns the String value from a List<String> keyPath

Implementation

dynamic getPathValue(List<String> keyPath, Map<String, dynamic> map) {
  dynamic getToNextLvl(String level, Map<String, dynamic> map) => map[level];

  Map<String, dynamic> tempLvlMap = map;
  dynamic value = '';

  for (var level in keyPath) {
    dynamic tmp = getToNextLvl(level, tempLvlMap);
    if (level != keyPath.last) {
      tempLvlMap = tmp;
    } else {
      value = tmp;
    }
  }

  return value;
}